Docs
Functions

createAuthAdapter

Build a custom auth adapter that resolves the caller's identity.

createAuthAdapter declares a custom auth adapter, typed against the AuthAdapter contract. Kizlo calls it to resolve who is making a request, mapping your session to a WordPress user. Register the result on createKizlo's adapters.auth.

Reach for this when you bring your own session layer. For common providers, use a prebuilt adapter instead. Those live in the adapter guides, not here.

Parameters

createAuthAdapter(adapter)

Prop

Type

getUser returns the resolved user, whose id is the WordPress user the caller maps to:

Prop

Type

Returns

The adapter, unchanged. createAuthAdapter only attaches the AuthAdapter type so you get inference and one documented entry point.

Examples

src/lib/kizlo/adapters/auth.ts
import { createAuthAdapter } from "kizlo"
import { getSession } from "../session"

export const auth = createAuthAdapter({
  async getUser(request) {
    const session = await getSession(request)
    if (!session) return null

    return {
      id: session.wpUserId,
      firstName: session.firstName,
      lastName: session.lastName,
      email: session.email,
    }
  },
})

Register it:

src/lib/kizlo/server/index.ts
import { createKizlo } from "kizlo"
import { auth } from "../adapters/auth"

export const { client, handler } = createKizlo({
  adapters: { auth },
})

On this page