Passed
Pull Request — master (#406)
by
unknown
01:44
created

LogoutController.post   A

Complexity

Conditions 2

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
dl 0
loc 12
rs 9.9
c 0
b 0
f 0
1
import {
2
  Controller,
3
  InternalServerErrorException,
4
  Post,
5
  Req,
6
  Res
7
} from '@nestjs/common';
8
import { Request, Response } from 'express';
9
import { WithName } from 'src/Infrastructure/Common/ExtendedRouting/WithName';
10
11
@Controller('logout')
12
export class LogoutController {
13
  @Post()
14
  @WithName('logout')
15
  public async post(@Req() req: Request, @Res() res: Response): Promise<void> {
16
    const err = await new Promise(resolve => {
17
      req.logout(err => resolve(err));
18
    });
19
20
    if (err) {
21
      throw new InternalServerErrorException('Failed to log out');
22
    }
23
24
    res.redirect(303, '/login');
25
  }
26
}
27