← @mortar-kit/auth

MiddlewareOptionsinterface

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

interface MiddlewareOptions

Options for createMiddleware.

Properties

auth: Auth<unknown>

The site's createAuth (or authFromEnv).

blobs?: BlobStore

Serves uploaded files from this store at the path its url('') gives (e.g. /uploads/), with serveBlob.

rateLimit?: false | { max: number; window: number }

Limits sign-in attempts (posts to the auth routes) per client: max in each window of seconds, then 429 with Retry-After. Asking for a code or link and trying one count separately, so a client that used up its sends can still type the code it got. Default { max: 10, window: 600 } for each; false turns it off. Kept in memory, per server process.

clientKey?: (request: Request) => string | undefined

Who a request is from, for the rate limit; undefined means not limited. Default: the first address in X-Forwarded-For, else X-Real-IP, which a proxy in front of the server sets. Without a proxy, a Fetch Request doesn't carry the client's address: pass your own (a shared bucket for everyone would let one client lock every editor out).

csp?: string | boolean

A Content-Security-Policy for HTML responses. true (default) sends script-src 'nonce-…' 'strict-dynamic'; object-src 'none'; base-uri 'none'; frame-ancestors 'self', with a fresh nonce per request that the page render puts on its scripts; a string is your own policy, where {nonce} is replaced by that nonce; false sends none. The server entry must pass the nonce to renderToStream (the plugin's generated entries do). Default off on the dev server (dev), since Vite's dev scripts carry no nonce.

headers?: false | Readonly<Record<string, string | null>>

Headers for every response, unless it set them itself. Default X-Content-Type-Options: nosniff, Referrer-Policy: strict-origin-when-cross-origin and X-Frame-Options: SAMEORIGIN (the admin's preview is a same-origin frame). Yours are added to those; a header set to null is left out; false adds none.

sitemap?: { content: ContentSource; collections: readonly AnyCollection[] } & Omit<SitemapOptions, "origin"> & { origin?: string }

Answers GET /sitemap.xml with sitemap(content, collections, options) from @mortar-kit/core. origin defaults to the request's; set it behind a proxy (e.g. from MORTAR_BASE_URL).

robots?: string | boolean

Answers GET /robots.txt. true lets crawlers in everywhere but the auth's protected paths (/admin) and points them at the sitemap when sitemap is set; a string is the whole file. Default: not served.

dev?: boolean

Development: no CSP by default. Default Vite's import.meta.env.DEV.