auth.controller.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { Controller, Get, Post, Body, UseGuards, HttpCode } from '@nestjs/common'
  2. import { AuthService } from './auth.service'
  3. import { LoginDto, RegisterDto, RefreshDto } from './dto/login.dto'
  4. import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard'
  5. import { CurrentUser } from '../../common/decorators/current-user.decorator'
  6. @Controller('auth')
  7. export class AuthController {
  8. constructor(private readonly authService: AuthService) {}
  9. @Post('register')
  10. register(@Body() dto: RegisterDto) {
  11. return this.authService.register(dto)
  12. }
  13. @Post('login')
  14. @HttpCode(200)
  15. login(@Body() dto: LoginDto) {
  16. return this.authService.login(dto)
  17. }
  18. @Post('refresh')
  19. @HttpCode(200)
  20. refresh(@Body() dto: RefreshDto) {
  21. return this.authService.refresh(dto.refreshToken)
  22. }
  23. @Post('logout')
  24. @HttpCode(200)
  25. @UseGuards(JwtAuthGuard)
  26. logout(@Body() dto: RefreshDto) {
  27. return this.authService.logout(dto.refreshToken)
  28. }
  29. @Get('me')
  30. @UseGuards(JwtAuthGuard)
  31. me(@CurrentUser() user: { userId: string }) {
  32. return this.authService.getCurrentUser(user.userId)
  33. }
  34. @Get('health')
  35. health() {
  36. return { status: 'ok', phase: 'phase-2-auth' }
  37. }
  38. }