backend/config/jwt.ts
creations 8a9499be85
All checks were successful
Code quality checks / biome (push) Successful in 8s
re-order alot, move to bun redis, generalized
2025-05-18 09:53:23 -04:00

27 lines
593 B
TypeScript

const allowedAlgorithms = [
"HS256",
"RS256",
"HS384",
"HS512",
"RS384",
"RS512",
] as const;
type AllowedAlgorithm = (typeof allowedAlgorithms)[number];
function getAlgorithm(envVar: string | undefined): AllowedAlgorithm {
if (allowedAlgorithms.includes(envVar as AllowedAlgorithm)) {
return envVar as AllowedAlgorithm;
}
return "HS256";
}
export const jwt: {
secret: string;
expiration: string;
algorithm: AllowedAlgorithm;
} = {
secret: process.env.JWT_SECRET || "",
expiration: process.env.JWT_EXPIRATION || "1h",
algorithm: getAlgorithm(process.env.JWT_ALGORITHM),
};