Track Usage with Supabase/Firebase

Here's the architecture on tracking ARES usage with Supabase:

Partner Backend->>ARES API: Send HMAC-signed request (email + client_id + timestamp)
ARES API-->>Partner Backend: Allow/deny access + remaining credits
Partner Backend-->>Partner Frontend: Proceed/block action

Step 1: Configure .env File

Set your ARES environment variables

ARES_CLIENT_ID=your_client_id
ARES_CLIENT_SECRET=your_client_secret

# ... existing environment variables ... 

Step 2: Configure generateSignature Function

Create this function in your app (preferrably in a dedicated route for everything about ARES):

circle-exclamation
app/api/ares/route.ts
export function generateSignature(
  clientSecret: string,
  email: string,
  timestamp: string
) {
  const payload = `${email}|${timestamp}`;
  return crypto
    .createHmac("sha256", clientSecret)
    .update(payload)
    .digest("hex");
}

You will need to use a HMAC signature to access ARES's APIs.

Step 3: Create a Function to Access User's Information on ARES

circle-exclamation
triangle-exclamation
circle-info

This function is used to check whether the user signed in to your Supabase app have an ARES account by using their email. If they don't, it will return an error. Since Supabase doesn't support custom OAuth providers yet, this method is a temporary workaround.

Example Response from calling the GET method defined above:

Step 4: Create a Function to Track User's Usage

This will earn credits for your app and deduct the credits from the user's account.

triangle-exclamation

Example Response from the POST method of the route:

triangle-exclamation
circle-exclamation

Example: Button that costs 1 credit to click

Last updated