All files / src/auth auth.controller.ts

100% Statements 13/13
100% Branches 1/1
100% Functions 3/3
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 201x 1x     1x 4x     1x 1x       1x 2x 2x 1x      
import { Controller, Post, Req, UseGuards, Headers } from '@nestjs/common';
import { AuthService } from './auth.service';
 
@Controller('auth')
export class AuthController {
  constructor(private authService: AuthService) {}
 
  @Post('login')
  async login(@Req() req) {
    return this.authService.login(req.body.username, req.body.password);
  }
 
  @Post('logout')
  async logout(@Headers('authorization') authHeader: string) {
    const token = authHeader?.replace('Bearer ', '');
    if (!token) return { message: 'No token provided' };
    return this.authService.logout(token);
  }
}