31 lines
937 B
TypeScript
31 lines
937 B
TypeScript
import { Body, Controller, Get, Post } from '@nestjs/common'
|
|
import { AuthService } from './auth.service'
|
|
import { CreateUserDto } from 'src/users/dto/create-user.dto'
|
|
import { ApiTags } from '@nestjs/swagger'
|
|
import { LoginInputDto } from './dto/login-input.dto'
|
|
import { UserEntity } from 'src/users/entities/user.entity'
|
|
import { User } from 'src/common/decorators/user.decorator'
|
|
import { NeedAuth } from 'src/common/decorators/auth.decorator'
|
|
|
|
@ApiTags('auth')
|
|
@Controller()
|
|
export class AuthController {
|
|
constructor(private readonly authService: AuthService) {}
|
|
|
|
@Post('api/register')
|
|
async register(@Body() userData: CreateUserDto) {
|
|
return this.authService.register(userData)
|
|
}
|
|
|
|
@Post('api/login')
|
|
async login(@Body() user: LoginInputDto) {
|
|
return this.authService.login(user.email, user.password)
|
|
}
|
|
|
|
@NeedAuth()
|
|
@Get('api/profile')
|
|
async getUserInfo(@User() user: UserEntity) {
|
|
return user
|
|
}
|
|
}
|