我尝试设置req用户:
use(req: any, res: Response, next: () => {}) {
req.user = this.userService.getUserAuthenticated(req.cookies.t);
next();
}
但是req.cookies没有定义。
使用以下方式启用Cookie:
app.register(require('fastify-cookie'));
在ExecutionContext
中使用Interceptor
可以很好地工作,但是我需要葫芦色,并且需要canActivate
在Interceptor之前调用。
答案 0 :(得分:0)
在应用程序lifecycle of fastify中的onRequest挂钩中对cookie进行了解析,因此如果未定义,则您的使用之前发生,或者您没有cookie。
你能做什么?
1)从headers.raw手动将cookie切成小块。
2)用作cookie的onRequest句柄之后的钩子。