Connect Supabase
Push your Supabase users to Apex. The auth.users.id (a UUID) becomes your internal_user_id.
Option A — Database webhook on auth.users
The simplest path: a Supabase Database Webhook that fires on INSERT into auth.users (new signups). Point it at a tiny edge function or your backend that forwards to Apex.
// supabase/functions/apex-identity/index.ts (Deno edge function)
Deno.serve(async (req) => {
const { record } = await req.json(); // the new auth.users row
await fetch("https://app.apex.inc/api/v1/events", {
method: "POST",
headers: {
"content-type": "application/json",
"x-api-key": Deno.env.get("APEX_API_KEY")!, // apex_sk_...
},
body: JSON.stringify({
events: [
{
type: "user_signed_up",
email: record.email,
// Social logins land the profile photo in user metadata. Map it to
// the canonical `avatar_url` attribute for end-user photos in Apex.
data: {
userId: record.id,
avatar_url:
record.raw_user_meta_data?.avatar_url ??
record.raw_user_meta_data?.picture,
},
},
],
}),
}).catch(() => {});
return new Response("ok");
});
Create the webhook under Database → Webhooks: table auth.users, event INSERT, type "Supabase Edge Functions" → apex-identity.
Option B — Auth Hook (client) for returning users
To reconcile your existing base on next login and stitch the browser session, emit an identify when the Supabase session resolves:
import { supabase } from "./supabaseClient";
import { identify } from "@apex-inc/sdk";
supabase.auth.onAuthStateChange((_event, session) => {
const user = session?.user;
if (user) {
identify(user.id, {
email: user.email,
avatar_url: user.user_metadata?.avatar_url,
visitorId: getCookie("apex_vid"),
});
}
});
Info
Use both: the database webhook is the durable server-side signal for new
signups; the client onAuthStateChange reconciles your existing base on next
login and stitches the anonymous browser session.
Wire it up
- Create a workspace API key (
apex_sk_…) and set it as the edge function secret:supabase secrets set APEX_API_KEY=apex_sk_.... - Deploy:
supabase functions deploy apex-identity. - Create the
auth.usersINSERT webhook. - Add the client
onAuthStateChangesnippet.