Configuration

Configuration options for FortressAuth.

Full Configuration Example

import { FortressAuth } from '@fortressauth/core';

const fortress = new FortressAuth(repository, rateLimiter, emailProvider, {
  // Session configuration
  session: {
    ttlMs: 7 * 24 * 60 * 60 * 1000, // 7 days (default)
  },
  
  // Password requirements
  password: {
    minLength: 8,      // default: 8
    maxLength: 128,    // default: 128
    breachedCheck: {
      enabled: false,  // default: false
      threshold: 1,    // reject if found this many times
    },
  },
  
  // Email verification
  emailVerification: {
    ttlMs: 24 * 60 * 60 * 1000, // 24 hours (default)
  },
  
  // Password reset
  passwordReset: {
    ttlMs: 60 * 60 * 1000,     // 1 hour (default)
    maxActiveTokens: 3,        // max active tokens per user
  },
  
  // Account lockout
  lockout: {
    enabled: true,             // default: true
    maxFailedAttempts: 5,      // default: 5
    lockoutDurationMs: 15 * 60 * 1000, // 15 minutes (default)
  },
  
  // Rate limiting
  rateLimit: {
    enabled: true,             // default: true
    endpoints: {
      login: { maxAttempts: 5, windowMs: 60000 },
      signup: { maxAttempts: 3, windowMs: 60000 },
      passwordReset: { maxAttempts: 3, windowMs: 60000 },
      verifyEmail: { maxAttempts: 5, windowMs: 60000 },
    },
  },
  
  // URLs for email links
  urls: {
    baseUrl: 'https://yourdomain.com',
  },
});

Configuration Options

Session Configuration

OptionTypeDefaultDescription
session.ttlMsnumber604800000 (7 days)Session token time-to-live in milliseconds

Password Configuration

OptionTypeDefaultDescription
password.minLengthnumber8Minimum password length
password.maxLengthnumber128Maximum password length
password.breachedCheck.enabledbooleanfalseCheck passwords against Have I Been Pwned
password.breachedCheck.thresholdnumber1Reject if password found this many times in breaches

Email Verification Configuration

OptionTypeDefaultDescription
emailVerification.ttlMsnumber86400000 (24 hours)Email verification token TTL

Password Reset Configuration

OptionTypeDefaultDescription
passwordReset.ttlMsnumber3600000 (1 hour)Password reset token TTL
passwordReset.maxActiveTokensnumber3Maximum active reset tokens per user

Lockout Configuration

OptionTypeDefaultDescription
lockout.enabledbooleantrueEnable account lockout after failed attempts
lockout.maxFailedAttemptsnumber5Failed attempts before lockout
lockout.lockoutDurationMsnumber900000 (15 min)Lockout duration in milliseconds

Rate Limit Configuration

OptionTypeDefaultDescription
rateLimit.enabledbooleantrueEnable rate limiting
rateLimit.endpoints.loginobject-Rate limit config for login endpoint
rateLimit.endpoints.signupobject-Rate limit config for signup endpoint

URL Configuration

OptionTypeDefaultDescription
urls.baseUrlstringhttp://localhost:3000Base URL for email links

Environment Variables

When using the HTTP server package, configuration can be set via environment variables:

# Server
PORT=5000
HOST=0.0.0.0
NODE_ENV=production

# Database
DATABASE_URL=postgresql://user:pass@localhost:5432/auth

# URLs
BASE_URL=https://yourdomain.com
CORS_ORIGINS=https://yourdomain.com,https://app.yourdomain.com

# Email (Resend)
EMAIL_PROVIDER=resend
RESEND_API_KEY=re_xxxxx
EMAIL_FROM_ADDRESS=noreply@yourdomain.com
EMAIL_FROM_NAME=Your App

# Session
SESSION_TTL_MS=604800000

# Password
PASSWORD_MIN_LENGTH=8
PASSWORD_MAX_LENGTH=128
BREACHED_PASSWORD_CHECK=false

# Lockout
LOCKOUT_ENABLED=true
LOCKOUT_MAX_ATTEMPTS=5
LOCKOUT_DURATION_MS=900000

# Rate Limiting
RATE_LIMIT_ENABLED=true

TypeScript Types

import type { FortressConfig, FortressConfigInput } from '@fortressauth/core';

// FortressConfigInput - what you pass to the constructor
// FortressConfig - the resolved config with all defaults applied