@kaaarel/auth
Docs: Configuration
View .md

Configuration

const auth = createAuth({
  url, secret, db, methods,           // required
  appName, framework, access, email, pages,
  schema, basePath, session, cookie, trustedOrigins, ip,
  rateLimit, migrate, devLogin, onUserCreated,
  twoFactor, workspaces, tokens,      // modules
});

Required

Option Type Notes
url string The app's public URL. Cookies are Secure and __Host- when it is https.
secret string At least 32 characters. Encrypts the OAuth flow cookie and TOTP secrets. bunx kaarel-auth secret makes one.
db string | Db A Postgres URL (Bun only), or an adapter. See Database.
methods Method[] Any of password(), google(), github().

Methods

password({ verifyEmail: true, minLength: 10, legacyVerify })
google(clientId, clientSecret, { scopes, prompt })   // prompt default "select_account"
github(clientId, clientSecret, { scopes })
  • verifyEmail (default true): users must open the link in the verification e-mail before they can sign in with a password. With it off, nobody proves they own the e-mail: do not combine it with a domain allowlist. doctor warns about this.
  • legacyVerify(hash, password): checks hashes from an old system. A match signs in and replaces the hash with argon2id. See Migrating.
  • A Google or GitHub method with an empty client ID or secret is off. Its routes redirect with error=method_disabled. doctor warns about it.

Access

access: "open"                                  // default: anyone can sign up
access: "closed"                                // nobody signs up; create users with auth.users.create()
access: allowlist(process.env.ADMIN_EMAILS)     // "me@x.dev, @team.dev"
access: async (email) => isEmployee(email)      // your own rule

A function or allowlist applies to sign-up and to every sign-in. A user that the rule no longer allows gets access_denied.

Pages

The package links and redirects to your pages. It never renders them.

Page Default Used for
signIn /login requireUser() redirects here with ?next=
afterSignIn / After sign-in, when there is no next
afterSignOut / After POST /auth/sign-out
error signIn Redirect flows send errors here as ?error=<code>
verified afterSignIn After the user opens a verification link
resetPassword /reset-password The reset e-mail links here with ?token=
twoFactor /login/two-factor The code form, when the user has 2FA on
acceptInvite /invite The invite e-mail links here with ?token=

Other options

Option Default Notes
appName the URL's host name Shown in e-mails and the authenticator app
framework none tanstackStart() or nextjs(). Without it, use auth.withRequest(request). See Frameworks.
email console outside production { from, send, templates }. See E-mails.
schema "auth" Postgres schema for the tables
basePath "/auth" Where you mount auth.routes
session.days 30 Sessions used in their second half get a new full period
cookie.name "auth" Cookie names become __Host-auth_session etc.
trustedOrigins [] Extra origins allowed to call sign-in and other changes
ip last x-forwarded-for, then x-real-ip, then the socket address from the adapter Client IP for rate limits. Per-IP limits are skipped when no IP is known. Set it when your proxy chain is longer than one hop (for example Cloudflare in front of Caddy).
rateLimit true Turn off only in tests
migrate "auto" "manual" to run kaarel-auth migrate yourself
devLogin none An e-mail. /auth/dev signs in as it, only outside production on localhost, *.localhost or *.test.
onUserCreated none (user, tx) => Promise<void>. Runs in the same transaction as the user insert. Throw to cancel the sign-up.

Modules

twoFactor: true,                                     // or { issuer: "Acme" }
workspaces: { roles: ["owner", "admin", "member"] }, // highest first; the first is the owner
tokens: true,                                        // or { prefix: "acme" } → tokens look like acme_…

auth.twoFactor, auth.workspaces and auth.tokens exist only when their module is on. TypeScript knows this from the config.