Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async exchangeToken(
@requestBody() req: AuthRefreshTokenRequest,
): Promise {
const refreshPayload: RefreshToken = await this.refreshTokenRepo.get(
req.refreshToken,
);
if (!refreshPayload) {
throw new HttpErrors.Unauthorized(AuthErrorKeys.TokenExpired);
}
const authClient = await this.authClientRepository.findOne({
where: {
clientId: refreshPayload.clientId,
},
});
if (!authClient) {
throw new HttpErrors.Unauthorized(AuthErrorKeys.ClientInvalid);
}
return this.createJWT(
{clientId: refreshPayload.clientId, userId: refreshPayload.userId},
authClient,
);
}