Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 控制器don';t返回结果而不重播。使用fastify平台发送_Javascript_Node.js_Typescript_Nestjs_Fastify - Fatal编程技术网

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);
}