Authenticate with the HelpGenie API using Bearer tokens from Supabase Auth
All API requests require a valid Bearer token in the Authorization header. Tokens are issued by Supabase Auth and tied to the authenticated user’s session.
Authenticate with Supabase Auth to obtain an access token. The exact method depends on your authentication flow (email/password, magic link, OAuth, etc.).
Copy
import { createClient } from "@supabase/supabase-js";const supabase = createClient( "https://<project-ref>.supabase.co", "<anon-key>");// Sign in (email/password example)const { data, error } = await supabase.auth.signInWithPassword({ email: "user@example.com", password: "your-password",});// Get the access token from the sessionconst accessToken = data.session?.access_token;
Supabase access tokens expire after a set duration (typically 1 hour). The Supabase client library handles token refresh automatically when using supabase.auth.getSession() or supabase.auth.onAuthStateChange().If you manage tokens manually, watch for UNAUTHORIZED or INVALID_TOKEN errors and refresh the session:
Do not hard-code access tokens. They are short-lived and tied to individual user sessions. Always retrieve fresh tokens from the Supabase Auth session.