Skip to content

createAdminAuthAdapter

createAdminAuthAdapter(options): AdminAuthConfig

Defined in: packages/admin/src/admin-auth-adapter.ts:81

Creates a complete AdminAuthConfig from a single auth-instance factory.

Replaces the ~50 lines of manual AdminAuthConfig boilerplate that every cfast app copy-pastes in admin.server.ts. The adapter delegates every method to the auth instance returned by getAuth().

This function complements createAdminAuth from @cfast/auth — they produce the same result. The difference is where you import from:

  • import { createAdminAuth } from "@cfast/auth" — when you already depend on @cfast/auth in the file
  • import { createAdminAuthAdapter } from "@cfast/admin" — when you want the admin package to be the single import in admin.server.ts

AdminAuthAdapterOptions

Configuration with a getAuth factory.

AdminAuthConfig

A complete AdminAuthConfig object ready to pass to createAdmin() or createAdminLoader/createAdminAction.

import { createAdminAuthAdapter, createAdminLoader, createAdminAction, introspectSchema } from "@cfast/admin";
import { initAuth } from "~/auth.setup.server";
import { env } from "~/env";
import * as schema from "~/db/schema";
import { appDb } from "~/db/client";
const auth = createAdminAuthAdapter({
getAuth: () => initAuth({ d1: env.get().DB, appUrl: env.get().APP_URL }),
});
const adminConfig = {
db: appDb,
auth,
schema: schema as Record<string, unknown>,
requiredRole: "admin",
};
const tableMetas = await introspectSchema(adminConfig.schema);
export const adminLoader = createAdminLoader(adminConfig, tableMetas);
export const adminAction = createAdminAction(adminConfig, tableMetas);