20 lines
625 B
TypeScript
20 lines
625 B
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { PassportStrategy } from '@nestjs/passport';
|
|
import { ExtractJwt, Strategy } from 'passport-jwt';
|
|
import { Role } from '@prisma/client';
|
|
|
|
@Injectable()
|
|
export class JwtStrategy extends PassportStrategy(Strategy) {
|
|
constructor() {
|
|
super({
|
|
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
ignoreExpiration: false,
|
|
secretOrKey: process.env.JWT_SECRET || 'fallback-secret',
|
|
});
|
|
}
|
|
|
|
async validate(payload: { sub: string; email: string; role: Role }) {
|
|
return { userId: payload.sub, email: payload.email, role: payload.role };
|
|
}
|
|
}
|