Files
Censo_api/src/auth/jwt.strategy.ts
T

23 lines
645 B
TypeScript
Raw Normal View History

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