Overview
The folksbase API uses Supabase Auth for authentication. Clients obtain a JWT token from Supabase and pass it in theAuthorization header on every request. The API validates the token server-side by calling supabase.auth.getUser(token).
Authentication is not global — it’s applied per-route. Public endpoints like the health check and OpenAPI spec don’t require a token. All data endpoints (contacts, tags, imports, exports, settings, stats) do.
How It Works
- The client authenticates with Supabase using any supported method (email/password, magic link, OAuth)
- Supabase returns a JWT access token and a refresh token
- The client includes the access token in the
Authorizationheader for API requests - The API middleware validates the token by calling Supabase’s
getUserendpoint - If valid, the middleware extracts
userIdandworkspaceIdfrom the user metadata and attaches them to the request context
Passing the Token
Include the JWT in theAuthorization header using the Bearer scheme:
Bearer (note the space). Requests without a valid header receive a 401 response.
What the Middleware Extracts
When authentication succeeds, the middleware sets two values on the request context:| Field | Source | Description |
|---|---|---|
userId | user.id | The Supabase user ID (UUID) |
workspaceId | user.user_metadata.workspace_id | The workspace this user belongs to |
c.get('user'):
workspaceId, which is how folksbase implements workspace-level multi-tenancy. A user can only access contacts, tags, imports, and exports within their own workspace.
Error Responses
| Status | Code | When |
|---|---|---|
401 | UNAUTHORIZED | Missing or malformed Authorization header |
401 | UNAUTHORIZED | Token is invalid or expired |
401 | UNAUTHORIZED | User has no workspace_id in their metadata |
Token Lifecycle
Supabase JWTs have a configurable expiry (default: 1 hour). The frontend uses Supabase’s client library which handles token refresh automatically. If you’re building a custom client:- Store both the access token and refresh token
- Use the refresh token to obtain a new access token before the current one expires
- Handle
401responses by refreshing the token and retrying the request
Workspace Provisioning
When a new user signs up, a Supabase webhook fires to/api/webhooks. The webhook handler:
- Creates a workspace for the user
- Creates default settings for the workspace
- Stores the
workspace_idin the user’s metadata - Queues a welcome email (sent after email confirmation)