33 lines
982 B
TypeScript
33 lines
982 B
TypeScript
import { Body, Controller, Get, Post, Req, UseGuards } from '@nestjs/common';
|
|
import { AuthService } from './auth.service';
|
|
import { LoginDto } from './dto/login.dto';
|
|
import { JwtAuthGuard } from './jwt-auth.guard';
|
|
import type { AuthenticatedRequest } from './jwt-auth.guard';
|
|
import { RefreshTokenDto } from './dto/refresh-token.dto';
|
|
|
|
@Controller('auth')
|
|
export class AuthController {
|
|
constructor(private readonly authService: AuthService) {}
|
|
|
|
@Post('login')
|
|
login(@Body() loginDto: LoginDto) {
|
|
return this.authService.login(loginDto);
|
|
}
|
|
|
|
@Post('refresh')
|
|
refresh(@Body() refreshTokenDto: RefreshTokenDto) {
|
|
return this.authService.refresh(refreshTokenDto);
|
|
}
|
|
|
|
@Post('logout')
|
|
@UseGuards(JwtAuthGuard)
|
|
logout(@Req() request: AuthenticatedRequest) {
|
|
return this.authService.logout(request.user!.sub);
|
|
}
|
|
|
|
@Get('me')
|
|
@UseGuards(JwtAuthGuard)
|
|
me(@Req() request: AuthenticatedRequest) {
|
|
return this.authService.me(request.user!.sub);
|
|
}
|
|
} |