/** * The `middleware` map to pass to stx-serve, overriding its existence-only * built-ins with token-validating equivalents. */ export declare function stxPageAuthMiddleware(options?: PageGateOptions): Record<'auth' | 'guest', StxPageMiddleware>; /** * The stx page gate, with the token actually validated. * * bun-plugin-stx's built-in `auth` / `guest` middleware — the pair behind * `definePageMeta({ middleware: ['auth'] })` — checks only that the auth * cookie EXISTS. `document.cookie = 'auth-token=x'` in a console satisfied it * on every protected page, and a stale cookie trapped a signed-out visitor on * `guest` pages (stacksjs/stacks#2274). * * stx-serve builds its registry as `{ ...builtInMiddleware, ...options.middleware }`, * so entries supplied here win over the built-ins by construction. These * validate the cookie's token exactly as a bearer token would be — through * `Auth.getUserFromToken()`, so a forged, revoked or expired token redirects * the same as no token at all. * * This gates SSR page rendering; API requests validate their own credentials. * Both the dev views server and `buddy serve` register it. */ declare interface StxPageContext { cookies: Record redirect: (to: string, status?: number) => Response } export declare interface PageGateOptions { cookieName?: string redirectTo?: string home?: string validate?: (token: string) => Promise } declare type StxPageMiddleware = (req: Request, ctx: StxPageContext) => Promise;