Skip to content

createAuthRouteHandlers

createAuthRouteHandlers(getAuth): object

Defined in: packages/auth/src/route-handlers.ts:36

Creates loader and action handlers for a React Router auth catch-all route.

The returned handlers forward all requests to the Better Auth handler via the AuthInstance obtained from the getAuth callback. Use this in a splat route (e.g., routes/auth.$.tsx) to handle magic link callbacks, passkey endpoints, and other Better Auth API routes.

getAuth can be either:

  • () => AuthInstance — for the simple, single-tenant case.
  • (request) => AuthInstance — for multi-tenant deployments that need to construct the auth instance from the request (e.g. resolving passkeys.rpId from the request hostname).

A factory function that returns a fully initialized AuthInstance. Called on every request so that the instance uses the correct per-request D1 binding.

(request) => AuthInstance | () => AuthInstance

object

An object with loader and action functions compatible with React Router route modules.

action: (__namedParameters) => Promise<Response> = handleRequest

Request

Promise<Response>

loader: (__namedParameters) => Promise<Response> = handleRequest

Request

Promise<Response>

// routes/auth.$.tsx
import { createAuthRouteHandlers } from "@cfast/auth";
import { initAuth } from "~/auth.setup.server";
import { env } from "~/env";
const { loader, action } = createAuthRouteHandlers((request) => {
const e = env.get();
return initAuth({ d1: e.DB, appUrl: e.APP_URL }, request);
});
export { loader, action };