Lumen
Integrations

Supabase

Integrate Lumen with Supabase

Automatically assign your free plan to new users

In order for entitlements to work, all your users should have a plan assigned. We recommend automatically assigning your free plan to every new user in your auth system.

Requirements

You must have an active free plan. If you don't, create one at Plans.

Installation

  1. Create a new webhook triggered on insert into the auth.users table in Supabase. Visit this URL (replace with your Supabase project URL):

    https://supabase.com/dashboard/project/YOUR_PROJECT_ID/integrations/webhooks/webhooks
  2. Set the webhook URL to:

    https://api.getlumen.dev/v1/webhooks/supabase
  3. Add the following header:

    • Header name: Authorization
    • Header value: Bearer your_secret_api_key

    If you don't have an API Key, you can create one at API Keys.

    Supabase webhook

UI Components

You only need to do this if you want to use our built-in UI Components Pricing Table, Usage Badge.

If you are using NextJS, you will need to add this code in api/lumen/[...all]/route.ts. Using another framework and have questions? Email us at founders@getlumen.dev and we will reply in less than 1h if we are awake.

import { NextRequest, NextResponse } from "next/server";
import { createClient } from "@/lib/supabase/server";
import { lumenNextHandler } from "@getlumen/server";

const handler = async (request: NextRequest) => {
  const supabase = await createClient();
  const {
    data: { user },
  } = await supabase.auth.getUser();

  if (!user) {
    return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
  }

  return NextResponse.json(
    await lumenNextHandler({
      request,
      userId: user.id,
    })
  );
};

export {
  handler as GET,
  handler as POST,
  handler as PUT,
  handler as DELETE,
  handler as PATCH,
  handler as OPTIONS,
  handler as HEAD,
};