Я делаю прототип аутентификации и авторизации, используя jwt, nest js, typescript
@EntityRepository(User)
export class UserRepository extends Repository<User> {
constructor(private jwtService: JwtService) { super() }
// few other methods
//this is the function
getProfile(req) {
const token = req.headers['authorization'].replace('Bearer', '').trim(); //token is okay
const decoded = this.jwtService.decode(token); //TypeError: this.jwtService.decode is not a function
console.log(decoded);
return decoded;
}
Мы 3 человека, работающие над этим тестовым проектом ERP, один из парней должен был сделать административную проверку для регистрации и использовал jwtService на отдельном промежуточном программном обеспечении, и это сработало, но для меня это не так?
EDIT:
Вот auth.module:
@Module({
imports: [
PassportModule.register({ defaultStrategy: 'jwt' }),
TypeOrmModule.forFeature([UserRepository]),
JwtModule.register({
secret: secret,
signOptions: {
expiresIn: 3600,
},
}),
],
controllers: [AuthController],
providers: [AuthService, JwtStrategy],
exports: [JwtStrategy, PassportModule]
})
export class AuthModule implements NestModule {
configure(consumer : MiddlewareConsumer) {
consumer
.apply(JwtTokenCheck)
.forRoutes({path: 'auth/signup', method: RequestMethod.POST})
}
}
Мы как бы исправили эту проблему, используя @authguard и @GetUser, мы новичок в фреймворках и все еще учимся, извините, если вопрос был глупым ...