midwayjs / midway

🍔 A Node.js Serverless Framework for front-end/full-stack developers. Build the application for next decade. Works on AWS, Alibaba Cloud, Tencent Cloud and traditional VM/Container. Super easy integrate with React and Vue. 🌈
https://www.midwayjs.org/
MIT License
7.38k stars 574 forks source link

Passport 登录后,用户信息反序列化函数里,依赖注入的数据库操作对象为空 #2262

Closed chenyuncai closed 2 years ago

chenyuncai commented 2 years ago

Passport 登录后用户信息反序列化函数里,依赖注入的数据库操作对象为空

您好,按照文档尝试集成passport做用户登录时,

@CustomStrategy()
export class LocalStrategy extends PassportStrategy(Strategy) {
  @InjectEntityModel(UserEntity)
  userModel: Repository<UserEntity>;
  async validate(username: string, password) {}
  serializeUser(user: UserEntity, done) {}
  async deserializeUser(username: string, done) {}
}

在validate函数中可以正常使用this.userModel进行数据库查询,但在deserializeUser里userModel为undedined。不能调用其下的数据库查询方法,validate与deserializeUser函数的执行机制有什么区别吗?

czy88840616 commented 2 years ago

可能 this 丢了。。

chenyuncai commented 2 years ago

是的,反序列化里打印this,this为undefined

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.