Guides / Signups & Auth

How to Get Notified on New Supabase Auth Signups

4 min readยทSignups & Auth

Why you need this

Supabase Auth handles the signup flow, but there's no built-in way to get notified when it happens. You can use Supabase Edge Functions, webhooks, or server-side auth callbacks.

Option 1: Server-side (Next.js API route)

If you're validating sessions server-side, call LogIt right after the user record is confirmed:

ts
// app/api/auth/callback/route.ts
import { createClient } from "@supabase/supabase-js";
import { logit } from "@/lib/logit";

export async function GET(request: Request) {
  const { searchParams } = new URL(request.url);
  const code = searchParams.get("code");

  if (code) {
    const supabase = createClient(
      process.env.NEXT_PUBLIC_SUPABASE_URL!,
      process.env.SUPABASE_SERVICE_KEY!
    );
    const { data: { user } } = await supabase.auth.exchangeCodeForSession(code);

    if (user?.created_at) {
      const isNew = new Date(user.created_at) > new Date(Date.now() - 5000);
      if (isNew) {
        await logit.now("signups", {
          event: "New Supabase user signed up",
          description: user.email ?? "Unknown",
          icon: "๐Ÿ‘ค",
          notify: true,
          tags: { provider: user.app_metadata?.provider ?? "email" },
          metadata: { userId: user.id, email: user.email },
        });
      }
    }
  }

  return Response.redirect(new URL("/dashboard", request.url));
}

Option 2: Supabase Edge Function (webhook)

Create a Supabase Edge Function triggered by the auth.users insert event:

ts
// supabase/functions/on-user-signup/index.ts
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";

serve(async (req) => {
  const payload = await req.json();
  const user = payload.record;

  await fetch("https://logit.now/api/v1/events", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ${Deno.env.get("LOGIT_API_KEY")}`,
    },
    body: JSON.stringify({
      channel: "signups",
      event: "New Supabase user",
      description: user.email,
      icon: "๐Ÿ‘ค",
      notify: true,
      metadata: { userId: user.id, provider: user.raw_app_meta_data?.provider },
    }),
  });

  return new Response("ok");
});

Then configure the webhook in your Supabase dashboard under Database โ†’ Webhooks, pointing to this function on the auth.users table INSERT event.

Environment

bash
LOGIT_API_KEY=lk_live_xxxxxxxxxxxxxxxx
NEXT_PUBLIC_SUPABASE_URL=https://xxx.supabase.co
SUPABASE_SERVICE_KEY=your-service-key

Try LogIt free

7-day trial. No credit card required.

Start free