| 1 | import { |
| 2 | Body, |
| 3 | Controller, |
| 4 | Get, |
| 5 | Post, |
| 6 | Request, |
| 7 | UseGuards, |
| 8 | } from '@nestjs/common'; |
| 9 | import { AuthServiceService } from './auth-service.service'; |
| 10 | import { LoginDto, RegisterDto } from '@app/common'; |
| 11 | import { AuthGuard } from '@nestjs/passport'; |
| 12 | |
| 13 | @Controller() |
| 14 | export class AuthServiceController { |
| 15 | constructor(private readonly authServiceService: AuthServiceService) {} |
| 16 | |
| 17 | @Post('register') |
| 18 | register(@Body() dto: RegisterDto) { |
| 19 | return this.authServiceService.register(dto.email, dto.password, dto.name); |
| 20 | } |
| 21 | |
| 22 | @Post('login') |
| 23 | login(@Body() dto: LoginDto) { |
| 24 | return this.authServiceService.login(dto.email, dto.password); |
| 25 | } |
| 26 | |
| 27 | @UseGuards(AuthGuard('jwt')) |
| 28 | @Get('profile') |
| 29 | getProfile(@Request() req: { user: { userId: string } }) { |
| 30 | return this.authServiceService.getProfile(req.user.userId); |
| 31 | } |
| 32 | } |