feat: v2 logout for bearer auth

This commit is contained in:
2024-05-25 21:41:34 +02:00
parent 8c8ad9789d
commit 9af6447757

View File

@@ -7,6 +7,7 @@ import {
Param,
Patch,
Post,
Req,
Request,
Res,
Response,
@@ -30,7 +31,7 @@ import {
ApiTags,
ApiUnauthorizedResponse,
} from '@nestjs/swagger'
import { Response as ExpressResponse } from 'express'
import { Request as ExpressRequest, Response as ExpressResponse } from 'express'
import { Cookies } from '../../infrastructure/decorators'
@@ -53,8 +54,8 @@ import {
ResendVerificationEmailCommand,
ResetPasswordCommand,
SendPasswordRecoveryEmailCommand,
VerifyEmailCommand,
UpdateUserCommand,
VerifyEmailCommand,
} from './use-cases'
@ApiTags('Auth')
@@ -181,6 +182,29 @@ export class AuthController {
return null
}
@Version('2')
@ApiOperation({ description: 'Sign current user out', summary: 'Sign current user out' })
@ApiUnauthorizedResponse({ description: 'Not logged in' })
@ApiNoContentResponse({ description: 'Logged out successfully' })
@HttpCode(HttpStatus.NO_CONTENT)
@UseGuards(JwtAuthGuard)
@Post('logout')
@ApiBearerAuth()
async logout2(
@Cookies('accessToken') accessToken: string,
@Req() req: ExpressRequest
): Promise<void> {
const authorization = req.headers.authorization
const token = authorization?.split(' ')[1]
if (!token) throw new UnauthorizedException()
await this.commandBus.execute(new LogoutCommand(token))
return null
}
@ApiOperation({
description: 'Deprecated, use v2',
summary: 'Deprecated, use v2',