분명 잘 구현한거같은데 해당 토큰을 넣고 테스트를 진행하면
자꾸 인증이 되지 않는다는 메세지를 보게되었을때 점검해봐야하는 부분이다.
다른 여러가지 부분을 확인해봐야하겠지만
내 구현엔 문제가 없는데... 이런생각이라면
import한 부분을 체크해보자.
import { PassportStrategy } from '@nestjs/passport';
import { Strategy } from 'passport-local'; # 여기가 문제
import { ExtractJwt } from 'passport-jwt';
export class GraphqlStrategy extends PassportStrategy(Strategy, 'jwt') {
constructor() {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
secretOrKey: process.env.JWT_SECRET,
usernameField: 'email',
passwordField: 'password',
});
}
async validate(token: string) {
return token;
}
}
위에서 문제는 passport-jwt와 passport-local을 호환해서 사용했기 때문이다.
import { PassportStrategy } from '@nestjs/passport';
import { ExtractJwt, Strategy } from 'passport-jwt';
export class GraphqlStrategy extends PassportStrategy(Strategy, 'jwt') {
constructor() {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
secretOrKey: process.env.JWT_SECRET,
usernameField: 'email',
passwordField: 'password',
});
}
async validate(token: string) {
return token;
}
}