diff --git a/backend/src/services/identity-access-token/identity-access-token-service.ts b/backend/src/services/identity-access-token/identity-access-token-service.ts index 47d1791d2..a51d80e41 100644 --- a/backend/src/services/identity-access-token/identity-access-token-service.ts +++ b/backend/src/services/identity-access-token/identity-access-token-service.ts @@ -78,9 +78,7 @@ export const identityAccessTokenServiceFactory = ({ const renewAccessToken = async ({ accessToken }: TRenewAccessTokenDTO) => { const appCfg = getConfig(); - const decodedToken = jwt.verify(accessToken, appCfg.AUTH_SECRET) as JwtPayload & { - identityAccessTokenId: string; - }; + const decodedToken = jwt.verify(accessToken, appCfg.AUTH_SECRET) as TIdentityAccessTokenJwtPayload; if (decodedToken.authTokenType !== AuthTokenType.IDENTITY_ACCESS_TOKEN) { throw new BadRequestError({ message: "Only identity access tokens can be renewed" }); } @@ -127,7 +125,23 @@ export const identityAccessTokenServiceFactory = ({ accessTokenLastRenewedAt: new Date() }); - return { accessToken, identityAccessToken: updatedIdentityAccessToken }; + const renewedToken = jwt.sign( + { + identityId: decodedToken.identityId, + clientSecretId: decodedToken.clientSecretId, + identityAccessTokenId: decodedToken.identityAccessTokenId, + authTokenType: AuthTokenType.IDENTITY_ACCESS_TOKEN + } as TIdentityAccessTokenJwtPayload, + appCfg.AUTH_SECRET, + // akhilmhdh: for non-expiry tokens you should not even set the value, including undefined. Even for undefined jsonwebtoken throws error + Number(identityAccessToken.accessTokenTTL) === 0 + ? undefined + : { + expiresIn: Number(identityAccessToken.accessTokenTTL) + } + ); + + return { accessToken: renewedToken, identityAccessToken: updatedIdentityAccessToken }; }; const revokeAccessToken = async (accessToken: string) => {