forked from Ynov/ptitspas-ynov-back
controller refresh token dto applied
This commit is contained in:
parent
0982f81dba
commit
18945edb51
@ -8,6 +8,7 @@ import { AuthGuard } from 'src/common/guards/auth.guard';
|
|||||||
import type { Request } from 'express';
|
import type { Request } from 'express';
|
||||||
import { UserService } from '../user/user.service';
|
import { UserService } from '../user/user.service';
|
||||||
import { ProfileResponseDto } from '../user/dto/profile_response.dto';
|
import { ProfileResponseDto } from '../user/dto/profile_response.dto';
|
||||||
|
import { RefreshTokenDto } from '../user/dto/refresh_token.dto';
|
||||||
|
|
||||||
@ApiTags('Authentification')
|
@ApiTags('Authentification')
|
||||||
@Controller('auth')
|
@Controller('auth')
|
||||||
@ -34,9 +35,12 @@ export class AuthController {
|
|||||||
|
|
||||||
@Public()
|
@Public()
|
||||||
@Post('refresh')
|
@Post('refresh')
|
||||||
|
@ApiBearerAuth('refresh_token')
|
||||||
|
@ApiResponse({ status: 200, description: 'Nouveaux tokens générés avec succès.' })
|
||||||
|
@ApiResponse({ status: 401, description: 'Token de rafraîchissement invalide ou expiré.' })
|
||||||
@ApiOperation({ summary: 'Rafraichir les tokens' })
|
@ApiOperation({ summary: 'Rafraichir les tokens' })
|
||||||
async refresh(@Body('refresh_token') refreshToken: string) {
|
async refresh(@Body() dto: RefreshTokenDto) {
|
||||||
return this.authService.refreshTokens(refreshToken);
|
return this.authService.refreshTokens(dto.refresh_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('me')
|
@Get('me')
|
||||||
@ -48,7 +52,6 @@ export class AuthController {
|
|||||||
if (!req.user || !req.user.sub) {
|
if (!req.user || !req.user.sub) {
|
||||||
throw new UnauthorizedException('Utilisateur non authentifié');
|
throw new UnauthorizedException('Utilisateur non authentifié');
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = await this.userService.findOne(req.user.sub);
|
const user = await this.userService.findOne(req.user.sub);
|
||||||
return {
|
return {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user