passport.js - NestJS 8 自己的 AuthGuard 和 Passport:无法读取未定义的属性“身份验证”
问题描述
我有自己的 AuthGuard 实现:
import { authenticate } from 'passport';
@Injectable()
export class AuthGuard implements CanActivate {
canActivate(context: ExecutionContext){
...
authenticate(...);
}
}
当我调用authenticate
方法时,我得到:Cannot read property 'authenticate' of undefined at Authenticator.authenticate (.../node_modules/passport/lib/authenticator.js:162:26
好像 Passport 还没有启动。
授权模块:
@Module({
imports: [PassportModule],
providers: [
AuthGuard,
{
provide: APP_GUARD,
useClass: AuthGuard,
},
],
})
export class AuthModule {}
和应用模块:
@Module({
imports: [
AuthModule
]
})
export class AppModule {}
这段代码在 Nest 7 中运行。
你知道有什么问题吗?
解决方案
推荐阅读
- firebase - 将 geoflutterfire 查询为 firestore
- python - 如何设置 MPU 传感器的采样率?
- python - 在多处理中发生错误时停止进程
- python - 如何在尝试中获取导致行的错误,除了使用python?
- python - 数据框日期时间将月份转换为天
- flutter - 调用 setState 时 Flutter Admob 的小部件出错
- html - 如何更改 React App 移动版的元素位置?
- python - 如何使用python在谷歌表格中的行尾追加
- twilio - Twilio > Google Ads 转化跟踪
- python - 在python中从数组中设置值