@@ -465,51 +465,51 @@ export class UserService {
465
465
if ( true === isPasskey && false === userData ?. isFidoVerified ) {
466
466
throw new UnauthorizedException ( ResponseMessages . user . error . registerFido ) ;
467
467
}
468
-
468
+ let tokenDetails ;
469
469
if ( true === isPasskey && userData ?. username && true === userData ?. isFidoVerified ) {
470
470
const getUserDetails = await this . userRepository . getUserDetails ( userData . email . toLowerCase ( ) ) ;
471
471
const decryptedPassword = await this . commonService . decryptPassword ( getUserDetails . password ) ;
472
- return await this . generateToken ( email . toLowerCase ( ) , decryptedPassword , userData ) ;
472
+ tokenDetails = await this . generateToken ( email . toLowerCase ( ) , decryptedPassword , userData ) ;
473
473
} else {
474
474
const decryptedPassword = await this . commonService . decryptPassword ( password ) ;
475
- const tokenDetails = await this . generateToken ( email . toLowerCase ( ) , decryptedPassword , userData ) ;
476
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
477
- const decodedToken : any = jwt . decode ( tokenDetails ?. access_token ) ;
478
- const sessionData = {
479
- id : decodedToken . sid ,
480
- sessionToken : tokenDetails ?. access_token ,
475
+ tokenDetails = await this . generateToken ( email . toLowerCase ( ) , decryptedPassword , userData ) ;
476
+ }
477
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
478
+ const decodedToken : any = jwt . decode ( tokenDetails ?. access_token ) ;
479
+ const sessionData = {
480
+ id : decodedToken . sid ,
481
+ sessionToken : tokenDetails ?. access_token ,
482
+ userId : userData ?. id ,
483
+ expires : tokenDetails ?. expires_in ,
484
+ refreshToken : tokenDetails ?. refresh_token ,
485
+ sessionType : SessionType . USER_SESSION
486
+ } ;
487
+
488
+ const fetchAccountDetails = await this . userRepository . checkAccountDetails ( userData ?. id ) ;
489
+ let addSessionDetails ;
490
+ let accountData ;
491
+ if ( null === fetchAccountDetails ) {
492
+ accountData = {
481
493
userId : userData ?. id ,
482
- expires : tokenDetails ?. expires_in ,
483
- refreshToken : tokenDetails ?. refresh_token ,
484
- sessionType : SessionType . USER_SESSION
494
+ keycloakUserId : userData ?. keycloakUserId ,
495
+ type : TokenType . BEARER_TOKEN
485
496
} ;
486
497
487
- const fetchAccountDetails = await this . userRepository . checkAccountDetails ( userData ?. id ) ;
488
- let addSessionDetails ;
489
- let accountData ;
490
- if ( null === fetchAccountDetails ) {
491
- accountData = {
492
- userId : userData ?. id ,
493
- keycloakUserId : userData ?. keycloakUserId ,
494
- type : TokenType . BEARER_TOKEN
495
- } ;
496
-
497
- await this . userRepository . addAccountDetails ( accountData ) . then ( async ( response ) => {
498
- const finalSessionData = { ...sessionData , accountId : response . id } ;
499
- addSessionDetails = await this . userRepository . createSession ( finalSessionData ) ;
500
- } ) ;
501
- } else {
502
- const finalSessionData = { ...sessionData , accountId : fetchAccountDetails . id } ;
498
+ await this . userRepository . addAccountDetails ( accountData ) . then ( async ( response ) => {
499
+ const finalSessionData = { ...sessionData , accountId : response . id } ;
503
500
addSessionDetails = await this . userRepository . createSession ( finalSessionData ) ;
504
- }
501
+ } ) ;
502
+ } else {
503
+ const finalSessionData = { ...sessionData , accountId : fetchAccountDetails . id } ;
504
+ addSessionDetails = await this . userRepository . createSession ( finalSessionData ) ;
505
+ }
505
506
506
- const finalResponse = {
507
- ...tokenDetails ,
508
- sessionId : addSessionDetails . id
509
- } ;
507
+ const finalResponse = {
508
+ ...tokenDetails ,
509
+ sessionId : addSessionDetails . id
510
+ } ;
510
511
511
- return finalResponse ;
512
- }
512
+ return finalResponse ;
513
513
} catch ( error ) {
514
514
this . logger . error ( `In Login User : ${ JSON . stringify ( error ) } ` ) ;
515
515
throw new RpcException ( error . response ? error . response : error ) ;
0 commit comments