@@ -78,9 +78,7 @@ export const identityAccessTokenServiceFactory = ({
78
78
const renewAccessToken = async ( { accessToken } : TRenewAccessTokenDTO ) => {
79
79
const appCfg = getConfig ( ) ;
80
80
81
- const decodedToken = jwt . verify ( accessToken , appCfg . AUTH_SECRET ) as JwtPayload & {
82
- identityAccessTokenId : string ;
83
- } ;
81
+ const decodedToken = jwt . verify ( accessToken , appCfg . AUTH_SECRET ) as TIdentityAccessTokenJwtPayload ;
84
82
if ( decodedToken . authTokenType !== AuthTokenType . IDENTITY_ACCESS_TOKEN ) {
85
83
throw new BadRequestError ( { message : "Only identity access tokens can be renewed" } ) ;
86
84
}
@@ -127,7 +125,23 @@ export const identityAccessTokenServiceFactory = ({
127
125
accessTokenLastRenewedAt : new Date ( )
128
126
} ) ;
129
127
130
- return { accessToken, identityAccessToken : updatedIdentityAccessToken } ;
128
+ const renewedToken = jwt . sign (
129
+ {
130
+ identityId : decodedToken . identityId ,
131
+ clientSecretId : decodedToken . clientSecretId ,
132
+ identityAccessTokenId : decodedToken . identityAccessTokenId ,
133
+ authTokenType : AuthTokenType . IDENTITY_ACCESS_TOKEN
134
+ } as TIdentityAccessTokenJwtPayload ,
135
+ appCfg . AUTH_SECRET ,
136
+ // akhilmhdh: for non-expiry tokens you should not even set the value, including undefined. Even for undefined jsonwebtoken throws error
137
+ Number ( identityAccessToken . accessTokenTTL ) === 0
138
+ ? undefined
139
+ : {
140
+ expiresIn : Number ( identityAccessToken . accessTokenTTL )
141
+ }
142
+ ) ;
143
+
144
+ return { accessToken : renewedToken , identityAccessToken : updatedIdentityAccessToken } ;
131
145
} ;
132
146
133
147
const revokeAccessToken = async ( accessToken : string ) => {
0 commit comments