add refresh token
This commit is contained in:
@@ -5,16 +5,20 @@ import { ConfigService } from '@nestjs/config';
|
||||
import { Role } from './role.enum';
|
||||
|
||||
@Injectable()
|
||||
export class JwtStrategy extends PassportStrategy(Strategy) {
|
||||
constructor(configService: ConfigService) {
|
||||
export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
|
||||
constructor(private configService: ConfigService) {
|
||||
super({
|
||||
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
||||
ignoreExpiration: false,
|
||||
// This is the critical fix: ensure the strategy uses the ConfigService
|
||||
// to get the secret at runtime.
|
||||
secretOrKey: configService.get<string>('JWT_SECRET') as string,
|
||||
});
|
||||
}
|
||||
|
||||
validate(payload: { sub: string; username: string; roles: Role[] }) {
|
||||
// The payload is already validated by passport-jwt at this point,
|
||||
// so we can trust its contents.
|
||||
validate(payload: { sub: number; username: string; roles: Role[] }) {
|
||||
return {
|
||||
userId: payload.sub,
|
||||
username: payload.username,
|
||||
|
||||
Reference in New Issue
Block a user