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.
Parameters
Section titled “Parameters”getAuth
Section titled “getAuth”() => 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.
Returns
Section titled “Returns”object
An object with loader and action functions compatible with React Router route modules.
action()
Section titled “action()”action: (
__namedParameters) =>Promise<Response> =handleRequest
Parameters
Section titled “Parameters”__namedParameters
Section titled “__namedParameters”request
Section titled “request”Request
Returns
Section titled “Returns”Promise<Response>
loader()
Section titled “loader()”loader: (
__namedParameters) =>Promise<Response> =handleRequest
Parameters
Section titled “Parameters”__namedParameters
Section titled “__namedParameters”request
Section titled “request”Request
Returns
Section titled “Returns”Promise<Response>
Example
Section titled “Example”// routes/auth.$.tsximport { 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 };