31 lines
812 B
TypeScript
31 lines
812 B
TypeScript
import { Body, Controller, Get, Post, UseGuards } from '@nestjs/common';
|
|
import {
|
|
CurrentUser,
|
|
type AuthenticatedUser,
|
|
} from '../common/current-user.decorator';
|
|
import { JwtAuthGuard } from '../common/jwt-auth.guard';
|
|
import { AuthService } from './auth.service';
|
|
import { LoginDto } from './dto/login.dto';
|
|
import { RegisterDto } from './dto/register.dto';
|
|
|
|
@Controller('auth')
|
|
export class AuthController {
|
|
constructor(private readonly authService: AuthService) {}
|
|
|
|
@Post('register')
|
|
register(@Body() dto: RegisterDto) {
|
|
return this.authService.register(dto);
|
|
}
|
|
|
|
@Post('login')
|
|
login(@Body() dto: LoginDto) {
|
|
return this.authService.login(dto);
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
@Get('me')
|
|
me(@CurrentUser() user: AuthenticatedUser) {
|
|
return this.authService.me(user.sub);
|
|
}
|
|
}
|