Skip to content

createAuthRouteHandlers

createAuthRouteHandlers(getAuth): object

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

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.

() => AuthInstance

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

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(() => {
const e = env.get();
return initAuth({ d1: e.DB, appUrl: e.APP_URL });
});
export { loader, action };