← @mortar-kit/auth

AuthOptionsinterface

import { AuthOptions } from '@mortar-kit/auth'

interface AuthOptions<User>

Options for createAuth.

Properties

methods: readonly AuthMethod[]

The ways to sign in, in the order the sign-in page lists them.

authorize: (input: AuthorizeInput) => User | Promise<User | null | undefined> | null | undefined

Who may use the admin: the user for this identity, or null if they may not. Runs when someone signs in and again on every guarded request, so removing someone takes effect at once; keep it quick (one lookup). The user is what user() and require() return; keep it plain JSON if it goes to the browser. allowEmails([...]) covers a fixed list.

secret: string | readonly string[]

Signs the session cookie and the OAuth state, and keys token hashes: at least 32 characters, from the environment, never in code. Several keys rotate: the first signs, all are accepted.

basePath?: string

Where the auth routes live. Default /admin/auth.

signInPath?: string

The app's sign-in page (a route rendering <SignIn> from @mortar-kit/admin). Default /admin/sign-in.

protect?: readonly string[]

Paths (prefixes) that need a signed-in user; handle redirects (GET) or refuses (401) the rest. Default ['/admin'].

home?: string

Where to go after signing in when no returnTo was given. Default /admin.

maxAge?: number

How long a session lasts, in seconds. Default 14 days.

cookieName?: string

The session cookie's name. Default mortar_session.

baseUrl?: string

The site's public origin, e.g. https://example.com: OAuth redirect URIs, email links and the same-origin check use it. Set it behind a proxy, where the request's own URL may be http://localhost:3000. Default: the origin of each request.