Skip to content
Browse documentation
typescript sdk

Connect Better Auth

Reuse native Better Auth session handling while exposing only verified identity to Smoothie.

Connect the server session adapter

Configure Better Auth natively, then wrap that instance. The adapter reads live sessions without silently refreshing or dropping cookies.

import { createBetterAuthSessionAdapter } from "@smoothie-framework/auth-better-auth";
import { createRequestAccess } from "@smoothie-framework/auth";
import { auth } from "./native-auth";

const access = createRequestAccess({
  sessions: createBetterAuthSessionAdapter(auth),
  trustedOrigins: ["https://app.example.com"],
});

Mount Better Auth's native handler separately and return its Response unchanged, including every Set-Cookie header. The application owns plugins, schema migrations, credential-handler rate limits and trustworthy client-address evidence. Do not trust arbitrary forwarded headers.

Retire client resources with the session

import {
  createAuthClient,
  createBetterAuthSessionScope,
} from "@smoothie-framework/auth-better-auth/client";

createAuthClient is the native client re-export. The optional session scope owns a resource created for each verified identity and disposes it on retirement; native external-store hooks can observe its snapshot. It does not add a second credential store or poller.

Use one identity-owned query scope when caching private data. Do not reuse the previous user’s cache after sign-out or identity change.