@@ -47,6 +47,7 @@ export class AuthService {
4747 email : dto . email ,
4848 hash,
4949 emailConfirmationToken,
50+ timezone : dto . timezone ,
5051 } ,
5152 } ) ;
5253 this . emailService . sendVerificationEmail (
@@ -58,6 +59,7 @@ export class AuthService {
5859 id : user . id ,
5960 nickname : user . nickname ,
6061 isEmailConfirmed : user . isEmailConfirmed ,
62+ timezone : user . timezone ,
6163 } ;
6264 } catch ( error ) {
6365 if ( error instanceof PrismaClientKnownRequestError ) {
@@ -87,10 +89,15 @@ export class AuthService {
8789 throw new ForbiddenException ( 'Password is incorrect' ) ;
8890 }
8991 const tokens = await this . signTokens ( user . id , user . email ) ;
90- await this . updateRtHash ( user . id , tokens . refreshToken ) ;
92+
93+ if ( dto . timezone && dto . timezone !== user . timezone ) {
94+ await this . updateLoginData ( user . id , tokens . refreshToken , dto . timezone ) ;
95+ } else {
96+ await this . updateLoginData ( user . id , tokens . refreshToken ) ;
97+ }
9198 return {
9299 tokens,
93- user : { email : user . email , id : user . id } ,
100+ user : { email : user . email , id : user . id , timezone : user . timezone } ,
94101 } ;
95102 }
96103
@@ -101,6 +108,7 @@ export class AuthService {
101108 email : userFromDB . email ,
102109 id : userFromDB . id ,
103110 isEmailConfirmed : userFromDB . isEmailConfirmed ,
111+ timezone : userFromDB . timezone ,
104112 } ;
105113 }
106114
@@ -127,7 +135,7 @@ export class AuthService {
127135 if ( ! rtMatches ) throw new ForbiddenException ( 'Rt token does not match' ) ;
128136
129137 const tokens = await this . signTokens ( user . id , user . email ) ;
130- await this . updateRtHash ( user . id , tokens . refreshToken ) ;
138+ await this . updateLoginData ( user . id , tokens . refreshToken ) ;
131139 return tokens ;
132140 }
133141
@@ -173,9 +181,9 @@ export class AuthService {
173181 } ) ;
174182
175183 const tokens = await this . signTokens ( user . id , user . email ) ;
176- await this . updateRtHash ( user . id , tokens . refreshToken ) ;
184+ await this . updateLoginData ( user . id , tokens . refreshToken ) ;
177185 this . sseService . sendToUser ( user . id , { type : 'email_verified' } ) ;
178- return { tokens, user : { email : user . email } } ;
186+ return { tokens, user : { email : user . email , timezone : user . timezone } } ;
179187 }
180188
181189 async changePassword (
@@ -262,15 +270,20 @@ export class AuthService {
262270 }
263271 }
264272
265- async updateRtHash ( id : string , rt : string ) {
273+ async updateLoginData ( id : string , rt : string , timezone ? : string ) {
266274 const hash = await argon2 . hash ( rt ) ;
275+ const updateData = { hashedRt : hash } as {
276+ hashedRt : string ;
277+ timezone ?: string ;
278+ } ;
279+ if ( timezone ) {
280+ updateData . timezone = timezone ;
281+ }
267282 await this . userRepository . update ( {
268283 where : {
269284 id,
270285 } ,
271- data : {
272- hashedRt : hash ,
273- } ,
286+ data : updateData ,
274287 } ) ;
275288 }
276289
0 commit comments