fix auth refresh endpoint and quiet expected 401 on profile check

This commit is contained in:
2026-06-26 13:23:03 +03:30
parent 6738ae225d
commit c1cffbcafa
3 changed files with 52 additions and 3 deletions

View File

@@ -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
// =========================