Reputation: 109
@Post('signin')
async signIn(@Body() account) {
return this.appService.signIn(account);
}
******************************
{
"success": true,
"message": "use cache",
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJ1c2VyMkB0ZXN0LmNvbSIsImlhdCI6MTYxMDY3NjkyNSwiZXhwIjoxNjEwNzEyOTI1fQ.Tx3a0brtWYD7GQUKYQAq_48biIZCFpqEQsds2-BrINc"
}
-----------------------------------
@Post('signin')
async signIn(@Body() account, @Res() res: Response) {
res.send({
result: this.appService.signIn(account)
})
}
******************************
{
"result": {}
}
I'm trying to send the result as Response.
But result is {} //undefined
if i using res.json()
or res.send()
Cookie-parser, app.use(cookieParser())
is already done.
Upvotes: 2
Views: 11567
Reputation: 70061
If your this.appService.login()
is an async
call, you need to await
the response before using res.send()
. Something like this should do
@Post('signin')
async signIn(@Body() account, @Res() res: Response) {
const result = await this.appService.signIn(account);
res.send({
result
});
}
Is there any reason you want to inject the @Res()
instead of letting Nest handle it?
Upvotes: 2