32 lines
763 B
TypeScript
32 lines
763 B
TypeScript
import {
|
|
Controller,
|
|
Post,
|
|
Body,
|
|
HttpCode,
|
|
HttpStatus,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { AuthService } from './auth.service';
|
|
import { LoginUserDto, CreateUserDto } from '../users/user.dto';
|
|
import { LocalAuthGuard } from './local-auth.guard';
|
|
import { Public } from './public.decorator';
|
|
|
|
@Controller('auth')
|
|
export class AuthController {
|
|
constructor(private readonly authService: AuthService) {}
|
|
|
|
@Public()
|
|
@UseGuards(LocalAuthGuard)
|
|
@Post('login')
|
|
@HttpCode(HttpStatus.OK)
|
|
async login(@Body() loginUserDto: LoginUserDto) {
|
|
return this.authService.login(loginUserDto);
|
|
}
|
|
|
|
@Public()
|
|
@Post('register')
|
|
async register(@Body() createUserDto: CreateUserDto) {
|
|
return this.authService.register(createUserDto);
|
|
}
|
|
}
|