Merge pull request #1 from ershisan99/master2

feat: v2 logout for bearer auth
This commit is contained in:
2024-05-25 21:43:45 +02:00
committed by GitHub

View File

@@ -7,6 +7,7 @@ import {
Param, Param,
Patch, Patch,
Post, Post,
Req,
Request, Request,
Res, Res,
Response, Response,
@@ -30,7 +31,7 @@ import {
ApiTags, ApiTags,
ApiUnauthorizedResponse, ApiUnauthorizedResponse,
} from '@nestjs/swagger' } from '@nestjs/swagger'
import { Response as ExpressResponse } from 'express' import { Request as ExpressRequest, Response as ExpressResponse } from 'express'
import { Cookies } from '../../infrastructure/decorators' import { Cookies } from '../../infrastructure/decorators'
@@ -53,8 +54,8 @@ import {
ResendVerificationEmailCommand, ResendVerificationEmailCommand,
ResetPasswordCommand, ResetPasswordCommand,
SendPasswordRecoveryEmailCommand, SendPasswordRecoveryEmailCommand,
VerifyEmailCommand,
UpdateUserCommand, UpdateUserCommand,
VerifyEmailCommand,
} from './use-cases' } from './use-cases'
@ApiTags('Auth') @ApiTags('Auth')
@@ -181,6 +182,29 @@ export class AuthController {
return null 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({ @ApiOperation({
description: 'Deprecated, use v2', description: 'Deprecated, use v2',
summary: 'Deprecated, use v2', summary: 'Deprecated, use v2',