当前位置: 首页 > 知识库问答 >
问题:

nestjs - NestJS中@Request()装饰器属性来源?

裴建华
2024-04-10

nestjs中@Request() request中属性的来源

看过请求中的响应头和请求头,没找到对应的属性

async login(@Request() request: any) {    if (request?.user?.fail) {      this.logProvider.login(request, false);      throw new UnauthorizedException({        statusCode: 401,        message: '用户名或密码错误!',      });    }

这里request?.user我找不到对应的来源,按理来说这个应该属于项目开发者自行添加的,但是我查了整个项目都没找到对应的赋值操作
这是对应的开源项目地址:https://github.com/Mereithhh/vanblog/blob/master/packages/server/src/controller/admin/auth/auth.controller.ts
没提issue的原因是我不确定这个是不是有其他的原因
当然在开发群里提问过了,然后就是维护者好像也不是很活跃,所以寄希望于社区大佬了。

共有1个答案

贺飞星
2024-04-10

在这里: https://github.com/Mereithhh/vanblog/blob/eabb38650cc1d0cc99c3896a190f3113a1bf7f47/packages/server/src/provider/auth/local.strategy.ts#L17

它用了 @nestjs/passport 这个插件,继承并实现自定义的 PassportStrategy,其 validate() 的返回值会自动被附加到 Request 对象上。

REF: https://docs.nestjs.com/recipes/passport
image.png
 类似资料:
  • 我有一个RESTAPI服务器,使用NestJS和typeorm,控制器上有CRUD装饰器。我有一个用户实体 我知道用户名也是主列(我有更多列),但我需要通过用户名和角色(或id)来识别用户 我还有另一个实体(家庭信息) 但是,当我试图获取所有家庭信息(localhost:3000/api/family info)时,会出现一个错误“column familyinfonentity.parent\u

  • Object.defineProperty(target, key, { writable: false }); } @ReadOnly // notice there are no `()` name: string; const t = new Test(); t.name = 'jan';

  • A collection of Badass modules and utilities to help you level up your NestJS application. Package Description Version Changelog @golevelup/nestjs-common Common types, mixins changelog @golevelup/nest

  • Description The rbac module for Nest. Installation npm i --save nestjs-rbac Quick Start For using RBAC there is need to implement IStorageRbac export interface IStorageRbac { roles: string[]; permis

  • Nestjs-BFF OVERVIEW Overview     Frontend     Backend     CLI     DevOps Status This library is currently 'on ice' and is no longer being activley maintained at this time. However, it may still server

  • rucken-core-nestjs A simple application demonstrating the basic usage of permissions with NestJS (JWT, Passport, Facebook, Google+, User, Group, Permission) based on Rucken template Screenshots Featur