feat: add backend-mock app
This commit is contained in:
29
apps/backend-mock/src/modules/auth/refresh-token.strategy.ts
Normal file
29
apps/backend-mock/src/modules/auth/refresh-token.strategy.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import type { JwtConfig, JwtPayload } from '@/types';
|
||||
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { PassportStrategy } from '@nestjs/passport';
|
||||
import { ExtractJwt, Strategy } from 'passport-jwt';
|
||||
|
||||
@Injectable()
|
||||
export class JwtRefreshStrategy extends PassportStrategy(
|
||||
Strategy,
|
||||
'jwt-refresh',
|
||||
) {
|
||||
constructor(configService: ConfigService) {
|
||||
super({
|
||||
ignoreExpiration: false,
|
||||
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
||||
secretOrKey: configService.get<JwtConfig>('jwt').refreshSecret,
|
||||
});
|
||||
}
|
||||
|
||||
async validate(payload: JwtPayload) {
|
||||
console.log('jwt refresh strategy validate payload', payload);
|
||||
return {
|
||||
id: payload.id,
|
||||
roles: payload.roles,
|
||||
username: payload.username,
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user