Data layer

Using Adapters

Adapters let you persist AuthCore data in any storage engine. Use the built-in Prisma adapter or provide your own implementation for Appwrite, Supabase, Drizzle, PlanetScale, or an internal API.

Adapter lifecycle

Resolve adapter at request timeAuthCore factories run inside each request. Build an adapter based on the tenant, region, or runtime config, then return the required CRUD primitives.Use getAdapter(req) for API routes and createAuthCoreAdapter() when composing your own server handlers.
Implement required methodsAdapters implement a small interface: user CRUD, session CRUD, token helpers, and optional organization helpers. Each property maps to the equivalent Prisma call in the default adapter.Type definitions live at dist/types/src/adapters/types.d.ts and are re-exported from codalware-auth as AuthCoreAdapter.
Wire the adapter into AuthCorePass the adapter to createAuthCoreServer() or configure({ adapter }). Every AuthCore API helper—magic links, checkout sessions, org flows—uses your adapter automatically.
Observe and optimiseUse lifecycle hooks to emit metrics and handle retries. Wrap persistence calls with logging and tracing so bottlenecks are easy to diagnose in production.Forward adapter events to your telemetry or audit pipeline so critical auth features stay observable.

Quick start

lib/authcore.ts

The default Prisma adapter ships with the package. For custom backends, implement the adapter contract shown below.

Authoring a custom adapter

lib/adapters/appwrite.ts

Tip: start from src/adapters/prisma.ts inside the package for a complete reference implementation.

Tenant-aware multi-region examples

Multi-tenant deployments often need different storage clusters. Compose adapters dynamically based on tenant metadata or request headers. The snippet below uses connection pools per region and records adapter diagnostics for observability.

lib/adapters/tenant-router.ts

Replace console.time with your telemetry of choice. The contract stays identical, so you can drop the router into existing AuthCore configuration.

Register the adapter per request

pages/api/auth/[...nextauth].ts

When you supply a custom adapter, every AuthCore helper—magic links, organization APIs, password reset flows—automatically uses it.