Files
Censo_api/src/auth/jwt.strategy.ts
T
2025-10-24 13:43:00 -06:00

23 lines
645 B
TypeScript

import { PassportStrategy } from "@nestjs/passport";
import{ExtractJwt,Strategy} from 'passport-jwt'
export class JwtStrategy extends PassportStrategy(Strategy){
constructor(){
if( !process.env.JWT ){
throw new Error('JWT_SECRET no está definido en las variables de entorno');
}
super({
jwtFromRequest:ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration:false,
secretOrKey:process.env.JWT
});
}
async validate(dataUser:any){
return {
id: dataUser.id,
nombre: dataUser.nombre,
tipoUsuario: dataUser.tipoUsuario,
};
}
}