26 lines
852 B
TypeScript
26 lines
852 B
TypeScript
import { Body, Controller, HttpCode, Inject, Post, forwardRef } from '@nestjs/common'
|
|||
|
|
import { Public } from '../common/decorators/public.decorator'
|
||
|
|
import { strictBodyPipe } from '../common/pipes/strict-body.pipe'
|
||
|
|
import { AuthService } from './auth.service'
|
||
|
|
import { LoginDto } from './dto/login.dto'
|
||
|
|
import { RegisterDto } from './dto/register.dto'
|
||
|
|
|
||
|
|
@Controller('api/auth')
|
||
|
|
export class AuthController {
|
||
|
|
constructor(@Inject(forwardRef(() => AuthService)) private readonly auth: AuthService) {}
|
||
|
|
|
||
|
|
@Public()
|
||
|
|
@HttpCode(200)
|
||
|
|
@Post('register')
|
||
|
|
register(@Body(strictBodyPipe(RegisterDto)) dto: RegisterDto) {
|
||
|
|
return this.auth.register(dto.username, dto.password, dto.name)
|
||
|
|
}
|
||
|
|
|
||
|
|
@Public()
|
||
|
|
@HttpCode(200)
|
||
|
|
@Post('login')
|
||
|
|
login(@Body(strictBodyPipe(LoginDto)) dto: LoginDto) {
|
||
|
|
return this.auth.login(dto.username, dto.password)
|
||
|
|
}
|
||
|
|
}
|