# Website Auth SDK Shared browser authentication flow and same-origin Cloudflare Pages facade. Websites retain their own UI; the SDK owns authentication state and navigation. Native apps, desktop apps and extensions use their own platform contracts. Public SDK documentation: https://website-auth-sdk.pages.dev/example. The same Pages site distributes the configuration documents linked below. Documentation generation runs only in the native Pages build; no SDK runtime, authentication route, secret or Service Binding is hosted by that project. ## Browser integration Use `createWebsiteAuthFlow` and subscribe the existing UI to its state. The [flow contract and example](configuration/FLOW.md) document configuration, commands, lifecycle, errors and remote verification. The browser transport factory is internal and is not a supported public import. ## Pages integration ```js import { createCookiePagesAuthHandler } from '@agentcore/website-auth/cloudflare-pages'; export const onRequest = createCookiePagesAuthHandler({ appSlug: 'your-product', bindingName: 'AUTH_SUPABASE_APP', }); ``` The Pages handler owns HttpOnly cookies and calls the authentication Worker through its private binding. Browser requests stay on `/api/auth`. Tokens never enter browser storage. `persistSession: false` also disables storage of public session metadata and uses a short-lived HttpOnly OAuth pending cookie. The authentication Worker's [example](https://auth-supabase-app.agentcore.workers.dev/example) owns the central HTTP contracts. Password recovery has a separate HttpOnly grant; see [recovery configuration](configuration/RECOVERY.md). For restricted test websites, set `allowedEmail: 'a44238587@gmail.com'` on both the auth handler and `createPagesWebsiteGuard`. Install the latter as root Pages middleware with exact public login paths. `createPagesAccessGuard` also protects individual Pages operations. This restriction is opt-in and does not change product website access. See the [owner-access contract](configuration/FLOW.md#website-specific-owner-access). ## Optional guest integration Use `website-auth-sdk/guest` for lazy guest identity issuance, expiration and observable state. `website-auth-sdk/guest-pages` supplies the same-origin issuance facade bound to the private `GuestAuth` entrypoint. See the [guest contract and example](configuration/GUEST.md). Guest credentials remain memory-only and never replace authenticated account cookies. Initialization does not issue requests; the product invokes guests only on explicit interactions. ## Server authentication email adapter Version 2.2.0 follows the owner's decision to use the existing quota service and accept possible duplicate emails. The dedicated email Durable Object, delivery journal and `email-durable-object` export are removed. Its packaged contracts pass in Dictum's remote Full deployment `70c06a29-0d5e-4463-84ad-056a4999ddc2`, exact consumer commit `1dd2ab7c7a6eda7ba4cdb195a5203a62968fa573`: six hook, five message and four mail-client tests, together with the existing authentication suite. Immutable archive SHA-256: `fecc8308fc8527ae925e00fc019da2b6ec68d633b16675f658c300c1c077da0a`. These mocked contracts do not prove real email delivery or sender provisioning. `website-auth-sdk/email-pages` verifies each Supabase event's raw Standard Webhooks signature, resolves an administrator-controlled application and prepares its configured messages. One installed route represents one trusted Supabase project. Each application configures its authorized Zebu Mail inbox, exact allowed return URLs, templates by action/language, trusted branding and an explicit fallback language. User-editable metadata may supply language; it cannot select a sender, account or project. Sender display names belong to the authorized inbox configuration. Renderers must escape user-derived HTML. The thirteen authentication/security actions include the two correctly mapped confirmations for a secure email change. The handler requires an `admitEmailAttempt` server callback. It must reserve each attempt through `quota-api`, using trusted policy and opaque recipient/IP identifiers, and throw on any refused or uncertain admission. Client requests must never supply quota thresholds or select a different mail account. This callback receives the configured project/application, signed event ID, action, recipient list, message count and a fresh server `requestId`/`createdAt` for each attempt. Repeated signed events retain their event ID but get different attempt identities, so every retry consumes quota. Its third argument provides the request's abort signal. Recipients must be HMAC-hashed before entering the quota ledger; neither raw recipients nor sender keys belong there. Settle admission before sending and retain charges on uncertain outcomes. A quota 429 carrying `quotaRetryAfter` becomes a hook 429 with `Retry-After`. Reset-request admission before Supabase is deployed in `auth-supabase-app`. `createAuthEmailQuotaAdmission` provides a concrete callback using the existing private `quota-api` binding. It reserves and settles each recipient before any mail preparation; the first reservation also charges the total message count against the application's project budget. All actions share the same rolling recipient/project pools. A two-recipient email change charges both recipients. Each retry gets fresh attempt identities. If a later admission fails, earlier charges remain; nothing is released after uncertainty. Policies are copied at construction and chosen only from trusted application configuration. Each application's policy supplies an explicit `quotaOwnerId`; the callback forwards it in reserve and settle bodies. Binding props and webhook metadata do not select the ledger. A stable, server-only HMAC secret isolates recipient hashes by project/application. Raw recipients, signed event IDs and mail credentials never enter quota bodies. Zero limits explicitly disable admission. Refusals, replays, mismatched receipts, failed settlement and uncertain transport prevent mail delivery. Every private reserve/settle call has its own deadline through bounded response EOF. This callback implementation is awaiting remote packaged tests. Real binding configuration and sender provisioning still need verification before activation; never install a no-op admission callback. Example server wiring (replace the trusted project, domain and inbox with verified account configuration; this is not an activated hook): ```js // functions/hooks/auth-email.js — server module only import { createAuthEmailHookHandler, createAuthEmailQuotaAdmission } from '@agentcore/website-auth/email-pages'; const projectId = 'project-one'; const admitEmailAttempt = createAuthEmailQuotaAdmission({ projectId, timeoutMs: 10000, getRecipientHashSecret: env => env.AUTH_EMAIL_QUOTA_HASH_SECRET, applications: { dictumflow: { quotaOwnerId: 'dictumflow', bindingName: 'AUTH_EMAIL_QUOTA', recipientLimit: 3, recipientWindowMs: 900000, projectLimit: 1000, projectWindowMs: 86400000, } }, }); export const onRequest = createAuthEmailHookHandler({ projectId, supabaseOrigin: 'https://project-one.supabase.co', bodyTimeoutMs: 10000, operationTimeoutMs: 10000, admitEmailAttempt, getHookSecret: env => env.SUPABASE_SEND_EMAIL_HOOK_SECRET, getMailApiKey: env => env.AUTH_EMAIL_ZEBUMAIL_API_KEY, applications: { dictumflow: { inboxId: '01234567-89ab-cdef-0123-456789abcdef', returnUrls: ['https://dictumflow.com/auth/callback/'], defaultReturnUrl: 'https://dictumflow.com/auth/callback/', fallbackLanguage: 'en', templates: { en: { recovery: ({link}) => ({ subject: 'Reset your password', text: link, }) } }, } }, }); ``` The example enables only the recovery template; configure each supported action and language explicitly. Supabase administrator metadata selects `dictumflow`; user metadata cannot authorize that application. The corresponding Pages configuration binds the quota ledger without a new Worker or Durable Object: ```json {"services":[{"binding":"AUTH_EMAIL_QUOTA","service":"quota-api"}]} ``` Keep the HMAC, hook and Zebu Mail secrets server-only. Their names in this example do not create credentials or provision a sender. Signature keys still belong to the configured Supabase project and Zebu Mail authorizes the selected inbox. After admission, the SDK calls Zebu Mail prepare/send directly from the Pages Function. The fixed API origin, manual redirects and validated matching RID prevent credential forwarding and false acceptance. The API authorizes the account key against its inbox and verified domain. Every HTTP call has its own `operationTimeoutMs` covering response EOF; `bodyTimeoutMs` bounds the signed body read independently. There is no global hook deadline or new email storage. The hook's abort signal reaches quota, prepare and send. A dependency response arriving after cancellation is discarded and its body cancelled. A retry may prepare a new identity and send another copy, including after a partially accepted two-recipient email change. The owner explicitly accepts this tradeoff. Quotas limit admitted requests/attempts; they do not guarantee single delivery. HTTP 200 `{}` is returned only after every required message is accepted by Zebu Mail. Signature, configuration, quota and provider failures remain explicit non-success responses. Provider acceptance is not proof of mailbox delivery. Real sender provisioning and complete password recovery must be verified before the Supabase hook is activated and its old Worker removed. ## Package distribution Consumers pin an immutable package archive, its SHA-256 sidecar and lockfile. Plain JavaScript builds copy the complete packaged ESM graph, preserving relative imports. Consumer projects never maintain editable copies of SDK implementation. Version 1 requires the shared flow. Validate each immutable release in the Dictum test website’s remote Full build before updating production consumers. ## Pages publication commands From this repository, publish canonical main with `github-publish-main "message"`. The shared launcher at scripts/project-command.mjs owns build admission and Fast/Full selection. Pages runs `npm run build:cloudflare`; a single `[cloudflare:full]` commit marker additionally runs the guarded `npm run check:full` after generating the same output. Local dev/build/test/deploy aliases are blocked. `publication.json` requires verification of the exact deployed commit. Install Git hooks with `git config core.hooksPath git-hooks`. No install lifecycle hook is added to packaged SDK consumers; their immutable archives remain unchanged. Quota adapters require explicit server-configured `quotaOwnerId`, independently of binding application metadata. Guest and email quota calls forward this value without deriving or normalizing it.