This commit is contained in:
commit
421043c9b5
67 changed files with 3455 additions and 0 deletions
28
environment/jwt.ts
Normal file
28
environment/jwt.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
import { getExpirationInSeconds } from "#lib/utils";
|
||||
import { validateJWTConfig } from "#lib/validation";
|
||||
|
||||
import type { JWTConfig } from "#types/config";
|
||||
|
||||
function createJWTConfig(): JWTConfig {
|
||||
const jwtSecret = process.env.JWT_SECRET || "";
|
||||
const jwtExpiration = process.env.JWT_EXPIRATION || "1h";
|
||||
const jwtIssuer = process.env.JWT_ISSUER || "";
|
||||
const jwtAlgorithm = process.env.JWT_ALGORITHM || "HS256";
|
||||
|
||||
const configForValidation: JWTConfig = {
|
||||
secret: jwtSecret,
|
||||
expiration: getExpirationInSeconds(jwtExpiration),
|
||||
issuer: jwtIssuer,
|
||||
algorithm: jwtAlgorithm,
|
||||
};
|
||||
|
||||
const validation = validateJWTConfig(configForValidation);
|
||||
|
||||
if (!validation.valid) {
|
||||
throw new Error(`JWT Configuration Error: ${validation.error}`);
|
||||
}
|
||||
|
||||
return configForValidation;
|
||||
}
|
||||
|
||||
export const jwt = createJWTConfig();
|
Loading…
Add table
Add a link
Reference in a new issue