Configuration

Last updated


This page lists every field of the Config passed to JWTAuth.init(), with defaults and validation rules.

Fields


FieldTypeRequiredDefaultDescription
privateKeyPathstringOne of two—Private key file path; overrides privateKey when set
privateKeystringOne of two—Private key PEM content
publicKeyPathstringOne of two—Public key file path; overrides publicKey when set
publicKeystringOne of two—Public key PEM content
accessTokenExpiresnumberYes—Access Token lifetime in seconds; also the revocation blacklist TTL
refreshTokenExpiresnumberYes—Refresh ID lifetime in seconds, reset on every refresh
isProdbooleanYes—Controls cookie secure, sameSite, and domain
domainstringNo—Cookie domain when isProd is true; when omitted, cookies are set without a domain attribute (host-only)
redis.hoststringYeslocalhostRedis host
redis.portnumberYes6379Redis port
redis.passwordstringNo—Redis password
redis.dbnumberNo0Redis database index
checkUserExists(userId: string) => Promise<boolean>Yes—Confirms the user still exists during refresh
AccessTokenCookieKeystringRequired by typeaccess_tokenAccess Token cookie name
RefreshTokenCookieKeystringRequired by typerefresh_idRefresh ID cookie name

init Validation and Errors


SituationResult
Neither publicKey nor publicKeyPathThrows publicKey is required
Neither privateKey nor privateKeyPathThrows privateKey is required
Key path does not existThe readFileSync error propagates unchanged
Redis connection failsLogged with console.error, then thrown

init() mutates the config object you pass: loaded keys are written back to publicKey / privateKey, and cookie names receive their defaults.

Key Sources


  1. import { JWTAuth } from "@pardnchiu/jwt-auth";
  2. // Read PEM content from environment variables, convenient for containers
  3. await JWTAuth.init({
  4. privateKey: process.env.JWT_PRIVATE_KEY,
  5. publicKey: process.env.JWT_PUBLIC_KEY,
  6. accessTokenExpires: 900,
  7. refreshTokenExpires: 604800,
  8. isProd: true,
  9. domain: "example.com",
  10. AccessTokenCookieKey: "access_token",
  11. RefreshTokenCookieKey: "refresh_id",
  12. redis: { host: "redis", port: 6379, password: process.env.REDIS_PASSWORD },
  13. checkUserExists: async (userId) => true,
  14. });

The package itself reads no environment variables.

Process Signals


Importing the package registers SIGINT and SIGTERM handlers that call JWTAuth.close() and then process.exit(0). If your app has its own graceful shutdown, note that this handler ends the process right after Redis disconnects.
Related: Token Transport, API Reference
中文