diff --git a/src/identity-and-account/authentication/controllers/auth.controller.ts b/src/identity-and-account/authentication/controllers/auth.controller.ts index cfc91ed..31e5f81 100644 --- a/src/identity-and-account/authentication/controllers/auth.controller.ts +++ b/src/identity-and-account/authentication/controllers/auth.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Get, Req, Res, UnauthorizedException, UseGuards } from '@nestjs/common'; +import { Controller, Get, Post, Req, Res, UnauthorizedException, UseGuards } from '@nestjs/common'; import { OIDCLoginGuard } from '../guards/authentik-auth.guard'; import { Request, Response } from 'express'; import { UsersService } from 'src/identity-and-account/users-management/services/users.service'; @@ -8,19 +8,19 @@ import { Access } from 'src/common/decorators/module-access.decorators'; export class AuthController { constructor( private readonly usersService: UsersService, - ){} + ) { } @UseGuards(OIDCLoginGuard) - @Get('/v1/login') + @Get('v1/login') login() { } - @Get('/callback') + @Get('callback') @UseGuards(OIDCLoginGuard) loginCallback(@Req() req: Request, @Res() res: Response) { res.redirect(process.env.REDIRECT_URL_DEV!); } - @Get('/me') + @Get('me') async getProfile( @Access('email') email: string, @Req() req: Request) { @@ -30,4 +30,19 @@ export class AuthController { return this.usersService.findOneByEmail(email); } + @Post('logout') + logout( + @Req() request: Request, + @Res() response: Response, + ) { + request.session.destroy(error => { + if (error) { + console.error('error during logout: ', error, 'user: ', request.user); + } + + response.clearCookie('connect.sid', { + path: '/', + }); + }) + } }