Answer the question
In order to leave comments, you need to log in
How to validate Request() req?
For @Request() req
Dto won't work as with @Body()?
import { Body, Controller, Get, Post, Request, UseGuards } from '@nestjs/common';
import { AuthService } from './auth/auth.service';
import { CreateRegisterDto } from './auth/dto/create-register.dto';
import { JwtAuthGuard } from './auth/guards/jwt-auth.guard';
import { LocalAuthGuard } from './auth/guards/local-auth.guard';
@Controller()
export class AppController {
constructor(private readonly authService: AuthService) {}
@UseGuards(LocalAuthGuard)
@Post('/login')
async login(@Request() req) {
return req.user;
//return this.authService.login();
//return req.user;
return this.authService.login(req.user);
}
//@UseGuards(LocalAuthGuard)
@Post('/register')
//async register(@Request() req) {
async register(@Body() createRegisterDto: CreateRegisterDto) {
return this.authService.register(createRegisterDto);
//return this.authService.register(req.body);
}
@UseGuards(JwtAuthGuard)
@Get('/profile')
getProfile(@Request() req) {
return req.user;
}
}
Answer the question
In order to leave comments, you need to log in
Write a custom decorator for user, and make a dto for it.
https://docs.nestjs.com/custom-decorators
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question