目前,我已经设法将AuthGuard与JWT身份验证结合使用,但是我没有设法继续进行user下去Roles。我尝试遵循cats示例,但从user未定义对象,您可以在第14行看到。这是我的代码:// auth.controller.ts@Controller('auth')@UseGuards(RolesGuard)export class AuthController { constructor(private readonly authService: AuthService) {} @Get('token') async createToken(): Promise<any> { return await this.authService.createToken(); } @Post() @UseGuards(AuthGuard()) @Roles('admin') findAll() { // this route is restricted by AuthGuard // JWT strategy return 'Super important info'; }}// auth.module.ts@Module({ imports: [ SharedModule, PassportModule.register({ defaultStrategy: 'jwt' }), JwtModule.registerAsync({ imports: [SharedModule], useFactory: async (configService: ConfigService) => ({ secretOrPrivateKey: configService.get('SECRET_KEY'), signOptions: { expiresIn: configService.get('SECRET_KEY_EXPIRES'), }, }), inject: [ConfigService], }), ], controllers: [AuthController], providers: [ AuthService, JwtStrategy, ],})export class AuthModule {}其余所有内容均与存储库中的示例完全相同。任何想法如何能够得到users定义?
添加回答
举报
0/150
提交
取消