2023-02-16 15:43:38 +08:00
|
|
|
import { Body, Controller, Get, Post } from '@nestjs/common'
|
2023-02-16 01:18:55 +08:00
|
|
|
import { AuthService } from './auth.service'
|
|
|
|
import { CreateUserDto } from 'src/users/dto/create-user.dto'
|
2023-02-16 16:41:34 +08:00
|
|
|
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger'
|
2023-02-16 01:18:55 +08:00
|
|
|
import { LoginInputDto } from './dto/login-input.dto'
|
2023-02-16 15:06:51 +08:00
|
|
|
import { UserEntity } from 'src/users/entities/user.entity'
|
|
|
|
import { User } from 'src/common/decorators/user.decorator'
|
2023-02-16 16:19:24 +08:00
|
|
|
import { SkipAuth } from 'src/common/decorators/skip-auth.decorator'
|
2023-02-16 01:18:55 +08:00
|
|
|
|
|
|
|
@ApiTags('auth')
|
|
|
|
@Controller()
|
|
|
|
export class AuthController {
|
|
|
|
constructor(private readonly authService: AuthService) {}
|
|
|
|
|
2023-02-16 16:19:24 +08:00
|
|
|
@SkipAuth()
|
2023-02-16 10:40:03 +08:00
|
|
|
@Post('api/register')
|
2023-02-16 01:18:55 +08:00
|
|
|
async register(@Body() userData: CreateUserDto) {
|
2023-02-16 10:40:03 +08:00
|
|
|
return this.authService.register(userData)
|
2023-02-16 01:18:55 +08:00
|
|
|
}
|
|
|
|
|
2023-02-16 16:19:24 +08:00
|
|
|
@SkipAuth()
|
2023-02-16 01:18:55 +08:00
|
|
|
@Post('api/login')
|
|
|
|
async login(@Body() user: LoginInputDto) {
|
|
|
|
return this.authService.login(user.email, user.password)
|
|
|
|
}
|
2023-02-16 12:09:48 +08:00
|
|
|
|
2023-02-16 16:41:34 +08:00
|
|
|
@ApiBearerAuth()
|
2023-02-16 12:09:48 +08:00
|
|
|
@Get('api/profile')
|
2023-02-16 15:06:51 +08:00
|
|
|
async getUserInfo(@User() user: UserEntity) {
|
|
|
|
return user
|
2023-02-16 12:09:48 +08:00
|
|
|
}
|
2023-02-16 01:18:55 +08:00
|
|
|
}
|