0.0.1 • Published 1 year ago
nestjs-local-jwt-strategy v0.0.1
nestjs-local-jwt
- Source From implementing-passport-jwt
implementing-passport-jwt
import { ExtractJwt, Strategy } from 'passport-jwt';
import { PassportStrategy } from '@nestjs/passport';
import { Injectable } from '@nestjs/common';
import { jwtConstants } from './constants';
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor() {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
secretOrKey: jwtConstants.secret,
algorithms: ['RS256'],
});
}
async validate(payload: any) {
return { userId: payload.sub, username: payload.username };
}
}
dependencies
npm install --save @nestjs/jwt passport-jwt
npm install --save-dev @types/passport-jwt
Read more
0.0.1
1 year ago