我最近使用nestjs。并且我编写了一个auth用户中间件,我想设置cookie并将用户信息设置为上下文。但是req.cookie()不存在, req.context类型错误
节点8.9 嵌套最新
@Injectable()
export class AuthUserMiddleware implements NestMiddleware {
constructor(private readonly userService: UserService) {
}
async use(req: Request, res: Response, next: Function) {
if (!req.context) {
req.context = {};
}
const uid = req.cookies.uid;
const user = await this.userService.refreshUser(uid);
req.cookies("uid", user.uid, {
httpOnly: false,
domain: config.domain,
path: "/"
});
req.context.user = user;
next();
}
}