> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agentonboard.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Supabase Auth

> Authenticate AI agents alongside Supabase Auth by mapping verified agent tokens to Supabase users and provisioning agent signups.

Supabase handles sessions and Row Level Security (RLS) for human web users; AgentOnboard authenticates AI agents calling your API.

## Copy-paste agent prompt

```text theme={null}
Integrate AgentOnboard with Supabase Auth in this repository.

1. Inspect the codebase and install `@agentonboard/sdk`.
2. Read these docs before editing:
   - https://docs.agentonboard.xyz/supabase.md
   - https://docs.agentonboard.xyz/verify.md
   - https://docs.agentonboard.xyz/accounts.md
   - https://docs.agentonboard.xyz/auth-md.md
3. Ask me three questions before writing code:
   - Which table (`profiles` or `users`) holds user emails, and which routes should accept agent tokens?
   - Should unknown emails return `403 ACCOUNT_REQUIRED` (reject) or create a verified user via `supabase.auth.admin.createUser` on `POST /api/signup`?
   - What is the production Domain hostname (e.g. `notes.com` or `api.notes.com`)?
4. Implement the integration following these invariants:
   - Use `requireAgentAccount` (and `createAgentAccount` on `POST /api/signup` if enabled).
   - Hardcode `audience` to the normalized production Domain.
   - Normalize emails with `normalizeEmail(email)` from `@agentonboard/sdk` (never raw `email.toLowerCase()`).
   - Serve the discovery file at both `/auth.md` and `/.well-known/auth.md` with matching `## Audience` and `403` instructions.
5. Verify against localhost by minting a test token with `POST https://agentonboard.xyz/api/v1/token/exchange` and testing `403 ACCOUNT_REQUIRED`, `200 OK`, and `401 INVALID_SIGNATURE`.
```

***

## 1. Verifying existing Supabase users

Use your Supabase service-role client inside `resolveAccount` to look up the user by normalized email:

```ts title="app/api/notes/route.ts" theme={null}
import { createClient } from "@supabase/supabase-js";
import { normalizeEmail } from "@agentonboard/sdk";
import { requireAgentAccount } from "@agentonboard/sdk/next";

const supabase = createClient(
  process.env.NEXT_PUBLIC_SUPABASE_URL!,
  process.env.SUPABASE_SERVICE_ROLE_KEY!,
);

export async function POST(request: Request) {
  const session = await requireAgentAccount(request, {
    audience: "notes.com",
    resolveAccount: async ({ email }) => {
      const { data } = await supabase
        .from("profiles")
        .select("id")
        .eq("email", normalizeEmail(email))
        .maybeSingle();

      return data?.id ?? null;
    },
  });

  // Returns 401 or 403 automatically
  if (!session.ok) return session.response;

  // session.user is your Supabase user ID (UUID)
  return Response.json({ success: true, supabase_user_id: session.user });
}
```

***

## 2. Enabling agent signup with Supabase

To let agents provision accounts on an explicit signup route, call the Supabase Admin Auth API:

```ts title="app/api/signup/route.ts" theme={null}
import { createClient } from "@supabase/supabase-js";
import { createAgentAccount, normalizeEmail } from "@agentonboard/sdk";

const supabase = createClient(
  process.env.NEXT_PUBLIC_SUPABASE_URL!,
  process.env.SUPABASE_SERVICE_ROLE_KEY!,
);

export async function POST(request: Request) {
  const outcome = await createAgentAccount({
    token: request.headers.get("Authorization") ?? "",
    audience: "notes.com",
    resolveAccount: async ({ email }) => {
      const { data } = await supabase
        .from("profiles")
        .select("id")
        .eq("email", normalizeEmail(email))
        .maybeSingle();
      return data?.id ?? null;
    },
    createAccount: async ({ email }) => {
      const { data, error } = await supabase.auth.admin.createUser({
        email: normalizeEmail(email),
        email_confirm: true,
      });

      if (error) throw error;
      return data.user.id;
    },
  });

  if (!outcome.ok) {
    return Response.json(
      { code: outcome.code, error: outcome.error },
      { status: outcome.code === "RESOLVER_ERROR" || outcome.code === "CONFIG_ERROR" ? 500 : 401 },
    );
  }

  return Response.json(
    { user_id: outcome.user, created: outcome.created },
    { status: 201 },
  );
}
```

> [!NOTE]
>
> **`email_confirm: true`**
>
> AgentOnboard verifies the User's email before issuing any token, so you can pass `email_confirm: true` without sending a duplicate confirmation email.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.