@@ -30,17 +30,17 @@ export class AuthService {
3030 public static PASSWORD_SALT_ROUNDS = 10 ;
3131
3232 async registerNewUser ( params : {
33- username : string ;
33+ email : string ;
3434 password : string ;
3535 name ?: string ;
3636 avatar ?: string ;
3737 bio ?: string ;
3838 } ) : Promise < UserEntity > {
39- const username = params . username ?. trim ( ) ;
39+ const email = params . email ?. trim ( ) ;
4040 const { password, name, avatar, bio } = params ;
4141
42- if ( ! username || username . length < 5 ) {
43- throw new BadRequestException ( 'Username must be of minimum 5 characters' ) ;
42+ if ( ! email || email . length < 5 ) {
43+ throw new BadRequestException ( 'email must be of minimum 5 characters' ) ;
4444 }
4545
4646 if ( ! password || password . length < 8 ) {
@@ -53,16 +53,16 @@ export class AuthService {
5353 ) ;
5454 }
5555
56- const usernameAlreadyExists = await this . userRepo . findOne ( {
57- where : { username } ,
56+ const alreadyExists = await this . userRepo . findOne ( {
57+ where : { email } ,
5858 } ) ;
5959
60- if ( usernameAlreadyExists ) {
61- throw new ConflictException ( 'This username is already taken !' ) ;
60+ if ( alreadyExists ) {
61+ throw new ConflictException ( 'This account is already exists !' ) ;
6262 }
6363
6464 const newUser = this . userRepo . create ( {
65- username ,
65+ email ,
6666 name,
6767 avatar,
6868 bio,
@@ -79,15 +79,17 @@ export class AuthService {
7979 userId : string ,
8080 password : string ,
8181 ) : Promise < PasswordEntity > {
82- const existing = await this . passwordRepo . findOne ( { where : { userId } } ) ;
82+ const existing = await this . passwordRepo . findOne ( {
83+ where : { user_id : userId } ,
84+ } ) ;
8385 if ( existing ) {
8486 throw new UnauthorizedException (
8587 'This user already has a password, cannot set new password' ,
8688 ) ;
8789 }
8890
8991 const newPassword = new PasswordEntity ( ) ;
90- newPassword . userId = userId ;
92+ newPassword . user_id = userId ;
9193 newPassword . password = await this . passToHash ( password ) ;
9294 return await this . passwordRepo . save ( newPassword ) ;
9395 }
@@ -96,24 +98,23 @@ export class AuthService {
9698 const user = await this . userRepo . findOne ( { where : { email } } ) ;
9799
98100 if ( ! user ) {
99- throw new NotFoundException ( 'Username does not exist' ) ;
101+ throw new NotFoundException ( 'Account does not exist' ) ;
100102 }
101103 const userPassword = await this . passwordRepo . findOne ( {
102- where : { userId : user . id } ,
104+ where : { user_id : user . id } ,
103105 } ) ;
104106 const passMatch = await this . matchPassHash ( password , userPassword . password ) ;
105107 if ( ! passMatch ) {
106108 throw new UnauthorizedException ( 'Password is wrong' ) ;
107109 }
108110 const session = new SessionsEntity ( ) ;
109- session . userId = userPassword . userId ;
111+ session . userId = userPassword . user_id ;
110112 const savedSession = await this . sessionRepo . save ( session ) ;
111113 await this . kafkaProducer . produce (
112114 {
113115 userId : user . id ,
114116 email : user . email ,
115117 sessionId : savedSession . id ,
116- username : user . username ,
117118 loggedInAt : new Date ( ) . toISOString ( ) ,
118119 } ,
119120 KafkaTopics . UserLoggedIn ,
0 commit comments