Skip to content

Commit d4c1523

Browse files
fix: session logic for passkey flow (#1404)
Signed-off-by: pranalidhanavade <[email protected]>
1 parent 0012787 commit d4c1523

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

apps/user/src/user.service.ts

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -465,51 +465,51 @@ export class UserService {
465465
if (true === isPasskey && false === userData?.isFidoVerified) {
466466
throw new UnauthorizedException(ResponseMessages.user.error.registerFido);
467467
}
468-
468+
let tokenDetails;
469469
if (true === isPasskey && userData?.username && true === userData?.isFidoVerified) {
470470
const getUserDetails = await this.userRepository.getUserDetails(userData.email.toLowerCase());
471471
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);
473473
} else {
474474
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 = {
481493
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
485496
};
486497

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 };
503500
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+
}
505506

506-
const finalResponse = {
507-
...tokenDetails,
508-
sessionId: addSessionDetails.id
509-
};
507+
const finalResponse = {
508+
...tokenDetails,
509+
sessionId: addSessionDetails.id
510+
};
510511

511-
return finalResponse;
512-
}
512+
return finalResponse;
513513
} catch (error) {
514514
this.logger.error(`In Login User : ${JSON.stringify(error)}`);
515515
throw new RpcException(error.response ? error.response : error);

0 commit comments

Comments
 (0)