32 lines
699 B
TypeScript
32 lines
699 B
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Post,
|
|
Get,
|
|
UseGuards,
|
|
Request,
|
|
} from '@nestjs/common';
|
|
import { AuthService } from './auth.service';
|
|
import { JwtAuthGuard } from './jwt.guard';
|
|
import { RegisterDto, LoginDto } from './dto/auth.dto';
|
|
|
|
@Controller('auth')
|
|
export class AuthController {
|
|
constructor(private authService: AuthService) {}
|
|
|
|
@Post('register')
|
|
register(@Body() body: RegisterDto) {
|
|
return this.authService.register(body.email, body.password);
|
|
}
|
|
|
|
@Post('login')
|
|
login(@Body() body: LoginDto) {
|
|
return this.authService.login(body.email, body.password);
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
@Get('profile')
|
|
getProfile(@Request() req: any) {
|
|
return req.user;
|
|
}
|
|
} |