25 lines
605 B
TypeScript
25 lines
605 B
TypeScript
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
|
|
})
|
|
}
|
|
|
|
async validate(payload: any) {
|
|
return {
|
|
id: payload.id,
|
|
email: payload.email,
|
|
name: payload.name,
|
|
roles: payload.roles
|
|
}
|
|
}
|
|
}
|