Skip to content

Configuration

createLiteAuth(config)

The factory accepts a single config object.

OptionTypeRequiredDefaultDescription
usersUser[]YesList of valid users. Use usersFromEnv() to load from env.
jwtSecretstringYesSecret used to sign and verify JWTs
cookieNamestringNo"lite-auth-token"Name of the httpOnly cookie
enabledbooleanNotrueWhen false, auth is disabled — all routes are open and handlers are no-ops

User shape

ts
type User = {
  email: string;
  password: string;
  role?: string;
  name?: string;
};

You can extend user objects with any additional fields — they will be included in the JWT payload and returned from /api/auth/me.

Environment variables

VariableDescription
LITE_AUTH_SECRETSecret for signing JWTs. Always required when auth is enabled.
LITE_AUTH_USERSJSON array of users. Used by usersFromEnv().
LITE_AUTH_ENABLEDSet to "false" to disable auth entirely.

Generate a strong secret:

bash
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"

Example

ts
// auth.ts
import { createLiteAuth, usersFromEnv } from "next-lite-auth";

export const auth = createLiteAuth({
  users: usersFromEnv(),
  jwtSecret: process.env.LITE_AUTH_SECRET!,
  enabled: process.env.LITE_AUTH_ENABLED !== "false",
  cookieName: "my-app-session", // optional
});
bash
# .env.local
LITE_AUTH_SECRET=your-long-random-secret-here
LITE_AUTH_ENABLED=true
LITE_AUTH_USERS=[{"email":"admin@example.com","password":"hunter2","role":"admin","name":"Admin"}]

Disabling auth

Set LITE_AUTH_ENABLED=false to open all routes without touching code. Useful for OSS projects where the deploying user may not need auth.

When enabled: false
MiddlewarePasses all requests through
POST /loginReturns { ok: true } (no-op)
POST /logoutReturns { ok: true } (no-op)
GET /meReturns { user: null }

Released under the MIT License.