# Integrating Autumn for Billing
The user is using Autumn to manage their pricing, which is a layer over Stripe that controls entitlements and payment flows.
DO NOT touch or suggest using any of Stripe’s APIs
DO NOT implement any pricing logic (subscription statuses, feature gating) at this stage. That will be handled afterwards.
## Before Integration
1. Before starting the integration, check the user has Auth in place. If they don’t, do not proceed.
2. Prompt them for an Autumn TEST API key. This should be saved in supabase as AUTUMN_SECRET_KEY. The user can generate an Autumn API key from [https://app.useautumn.com/sandbox/dev](https://app.useautumn.com/sandbox/dev)
## Integration steps
1. Install autumn-js: `npm install autumn-js`
2. Create a supabase edge function called `autumn`. Inside the function, use this code to route the requests correctly, and resolve the `customerId`. This will be the user’s ID from Supabase Auth.
/supabase/functions/autumn/index.ts
import { autumnHandler } from "npm:autumn-js/supabase";
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.49.9";
const corsHeaders = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization",
};
Deno.serve(async (req: Request) => {
if (req.method === "OPTIONS") {
return new Response("ok", { headers: corsHeaders });
}
const supabaseClient = createClient(
Deno.env.get("SUPABASE_URL") ?? "",
Deno.env.get("SUPABASE_ANON_KEY") ?? "",
{
global: {
headers: { Authorization: req.headers.get("Authorization") },
},
}
);
const { data, error } = await supabaseClient.auth.getUser();
const handler = autumnHandler({
corsHeaders,
identify: async () => {
return {
customerId: data.user?.id,
customerData: {
email: data.user?.email,
},
};
},
});
return handler(req);
});
1. Wrap the application with <AutumnProvider />. The backendUrl should direct to the supabase function, set includeCredentials as false and pass in the bearerToken from supabase auth.
The backendUrl should look like <PROJECT_ID>. [supabase.co/functions/v1/autumn](https://supabase.co). You may be able to import a supabase URL from env.
<AutumnProvider
backendUrl={`https://<PROJECT_ID>.supabase.co/functions/v1/autumn`}
includeCredentials={false}
getBearerToken={async () => {
const { data } = await supabase.auth.getSession();
return data.session?.access_token;
}}
>
<App />
</AutumnProvider>
1. Now verify that everything works by calling useCustomer() on the frontend somewhere in the app, and logging the response. Ask the user to check if the customer has been created in Autumn.
import { useCustomer } from "autumn-js/react";
const { customer } = useCustomer();
console.log("Autumn Customer", customer);