fix auth refresh endpoint and quiet expected 401 on profile check
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
HttpStatus,
|
||||
Get,
|
||||
Patch,
|
||||
UnauthorizedException,
|
||||
} from '@nestjs/common';
|
||||
import type { Response } from 'express';
|
||||
import {
|
||||
@@ -173,6 +174,33 @@ export class AuthController {
|
||||
);
|
||||
}
|
||||
|
||||
// =========================
|
||||
// REFRESH
|
||||
// =========================
|
||||
@Post('refresh')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@ApiOperation({ summary: 'Refresh access token using refresh cookie' })
|
||||
@ApiResponse({ status: 200, description: 'Access token refreshed' })
|
||||
@ApiUnauthorizedResponse({ description: 'Invalid or missing refresh token' })
|
||||
async refresh(@Req() req, @Res({ passthrough: true }) res: Response) {
|
||||
const refreshToken = req?.cookies?.refreshToken;
|
||||
|
||||
if (!refreshToken) {
|
||||
throw new UnauthorizedException('Refresh token not found');
|
||||
}
|
||||
|
||||
const result = await this.authService.refreshToken(refreshToken);
|
||||
|
||||
this.setAccessToken(res, result.data.accessToken);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
accessToken: result.data.accessToken,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// =========================
|
||||
// LOGOUT
|
||||
// =========================
|
||||
|
||||
Reference in New Issue
Block a user