Javascript 控制器don';t返回结果而不重播。使用fastify平台发送
我有登录路径,返回用户:Javascript 控制器don';t返回结果而不重播。使用fastify平台发送,javascript,node.js,typescript,nestjs,fastify,Javascript,Node.js,Typescript,Nestjs,Fastify,我有登录路径,返回用户: @Post('login') async login(@Body() user: LoginRequest, @Res() reply): Promise<User> { const foundUser = await this.authService.validateUser(user.email, user.password); reply.setCookie('t', foundUser._id, { path: '/' });
@Post('login')
async login(@Body() user: LoginRequest, @Res() reply): Promise<User> {
const foundUser = await this.authService.validateUser(user.email, user.password);
reply.setCookie('t', foundUser._id, { path: '/' });
// reply.send(foundUser);
return foundUser;
}
您必须从控制器函数中删除
@Res()reply
。一旦您注入响应
对象,许多嵌套特性就会停止工作,例如拦截器
@Post('login')
async login(@Body() user: LoginRequest): Promise<User> {
return this.authService.validateUser(user.email, user.password);
}
@Post('login'))
异步登录(@Body()用户:LoginRequest):承诺{
返回此.authService.validateUser(user.email,user.password);
}
您可以使用来动态设置cookie
@Post('login')
async login(@Body() user: LoginRequest): Promise<User> {
return this.authService.validateUser(user.email, user.password);
}