30 lines
846 B
TypeScript
30 lines
846 B
TypeScript
import { Body, Controller, Get, Post, Req, UseGuards } 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 { JwtAuthGuard } from './jwt-auth.guard'
|
|
|
|
@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)
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
@Get('api/profile')
|
|
async getUserInfo(@Req() req: any) {
|
|
console.log(req)
|
|
return req.user
|
|
}
|
|
}
|