You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
I just updated to v6.0.4 and I'm using authguard with graphql & passport-jwt. However, I'm getting Error: Unknown authentication strategy "jwt"
Expected behavior
Minimal reproduction of the problem with instructions
// gql-auth.guard.ts
import { Injectable } from '@nestjs/common';
import { GqlExecutionContext } from '@nestjs/graphql';
import { AuthGuard } from '@nestjs/passport';
@Injectable()
export class GqlAuthGuard extends AuthGuard('jwt') {
getRequest(context: GqlExecutionContext) {
const ctx = GqlExecutionContext.create(context);
return ctx.getContext().req;
}
}
//jwt.strategy.ts
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { ExtractJwt, Strategy, VerifiedCallback } from 'passport-jwt';
import { UserService} from 'src/user/user.service';
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(private userService: UserService) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
secretOrKey: process.env.JWT_SECRET,
});
}
async validate(payload: any, done: VerifiedCallback) {
const user = await this.userService.findOneByPayload(payload);
if (!user) {
return done(new UnauthorizedException(), false);
}
return done(null, { id: user.id }, payload.iat);
}
}
// auth.module.ts
import { Module } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
import { PassportModule } from '@nestjs/passport';
import { UserModule } from 'src/user/user.module';
import { AuthResolver } from './auth.resolver';
@Module({
imports: [
PassportModule.register({ defaultStrategy: 'jwt' }),
JwtModule.register({ secretOrPrivateKey: process.env.JWT_SECRET }),
UserModule,
],
providers: [AuthResolver],
})
export class AuthModule {}
What is the motivation / use case for changing the behavior?
Environment
Nest version: 6.0.4
For Tooling issues:
- Node version: 10.15
- Platform: Windows
Others:
The text was updated successfully, but these errors were encountered:
I'm submitting a...
Current behavior
I just updated to v6.0.4 and I'm using authguard with graphql & passport-jwt. However, I'm getting Error: Unknown authentication strategy "jwt"
Expected behavior
Minimal reproduction of the problem with instructions
What is the motivation / use case for changing the behavior?
Environment
The text was updated successfully, but these errors were encountered: