Spaces:
Sleeping
Sleeping
File size: 939 Bytes
c98875e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | import { Controller, Post, Body, Get, UseGuards, Request } from '@nestjs/common';
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';
import { AuthService } from './auth.service';
import { RegisterDto } from './dto/register.dto';
import { LoginDto } from './dto/login.dto';
@ApiTags('Auth')
@Controller('auth')
export class AuthController {
constructor(private authService: AuthService) {}
@Post('register')
@ApiOperation({ summary: 'Register a new user' })
register(@Body() dto: RegisterDto) {
return this.authService.register(dto);
}
@Post('login')
@ApiOperation({ summary: 'Login and get JWT' })
login(@Body() dto: LoginDto) {
return this.authService.login(dto);
}
@Get('me')
@ApiBearerAuth()
@UseGuards(AuthGuard('jwt'))
@ApiOperation({ summary: 'Get current user profile' })
me(@Request() req: any) {
return req.user;
}
}
|