|
|
@ -64,6 +64,10 @@ export class AdminService { |
|
|
|
expiresIn: this.configService.get<string | number>("JWT_REFRESH_EXPIRES") || "7d", |
|
|
|
expiresIn: this.configService.get<string | number>("JWT_REFRESH_EXPIRES") || "7d", |
|
|
|
}, |
|
|
|
}, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
await this.adminModel.update( |
|
|
|
|
|
|
|
{ refreshToken }, //
|
|
|
|
|
|
|
|
{ where: { id: admin.id } }, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
return { accessToken, refreshToken }; |
|
|
|
return { accessToken, refreshToken }; |
|
|
|
} catch (error) { |
|
|
|
} catch (error) { |
|
|
@ -73,6 +77,17 @@ export class AdminService { |
|
|
|
throw new HttpException("An unexpected error occurred. Please try again later.", HttpStatus.INTERNAL_SERVER_ERROR); |
|
|
|
throw new HttpException("An unexpected error occurred. Please try again later.", HttpStatus.INTERNAL_SERVER_ERROR); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//logout (delete refresh token from database)
|
|
|
|
|
|
|
|
async logout(userId: number) { |
|
|
|
|
|
|
|
const user = await this.adminModel.findOne({ |
|
|
|
|
|
|
|
where: { id: userId }, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
if (!user) { |
|
|
|
|
|
|
|
throw new HttpException("User not found.", HttpStatus.NOT_FOUND); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
await this.adminModel.update({ refreshToken: null }, { where: { id: userId } }); |
|
|
|
|
|
|
|
return { message: "logout is successful" }; |
|
|
|
|
|
|
|
} |
|
|
|
//getting new access token
|
|
|
|
//getting new access token
|
|
|
|
async newAccessToken(refreshToken: string) { |
|
|
|
async newAccessToken(refreshToken: string) { |
|
|
|
if (!refreshToken) { |
|
|
|
if (!refreshToken) { |
|
|
|