Implementation:24kchengYe MemoMind SupabaseTenantExtension authenticate
| Knowledge Sources | |
|---|---|
| Domains | Security, Authentication |
| Last Updated | 2026-10-28 00:00 GMT |
Overview
Concrete tool for authenticating requests via Supabase JWT validation with per-user schema isolation, using JWKS for asymmetric keys and fallback to the Supabase user endpoint.
Description
The SupabaseTenantExtension validates Supabase JWTs for multi-tenant isolation. Each authenticated user gets their own PostgreSQL schema, ensuring complete memory isolation between users. The schema name is derived from the user's Supabase user ID (the sub claim).
JWT verification:
- JWKS (preferred): when asymmetric keys (RS256) are configured in Supabase, the extension fetches the JWKS and verifies JWTs locally (no network call per request after initial fetch)
- Legacy fallback: for HS256 projects, falls back to the /auth/v1/user endpoint to validate the token
Schema naming: the user ID (UUID) is transformed into a valid schema name with underscores: "user_a1b2c3d4_e5f6_7890_abcd_ef1234567890".
The extension caches initialized schemas to avoid redundant migrations on repeated requests.
Usage
Configure this extension via HINDSIGHT_API_TENANT_EXTENSION when using Supabase for authentication in a multi-user deployment where each user needs isolated memory storage.
Code Reference
Source Location
- Repository: MemoMind
- File: engine/hindsight_api/extensions/builtin/supabase_tenant.py
- Lines: L89-433
Signature
class SupabaseTenantExtension(TenantExtension):
def __init__(self, config: dict[str, str]) -> None:
...
async def authenticate(self, context: RequestContext) -> TenantContext:
...
async def list_tenants(self) -> list[Tenant]:
...
Import
from hindsight_api.extensions.builtin.supabase_tenant import SupabaseTenantExtension
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| config["supabase_url"] | str | __init__ | Supabase project URL (required) |
| config["supabase_service_key"] | str | __init__ | Supabase service key (optional) |
| config["schema_prefix"] | str | __init__ | Schema name prefix (default "user") |
| context | RequestContext | authenticate | Request context with JWT token |
Outputs
| Name | Type | Description |
|---|---|---|
| tenant_context | TenantContext | Schema name derived from user ID (e.g., user_a1b2c3d4_...) |
Usage Examples
Configuring Supabase Auth
# In environment:
# HINDSIGHT_API_TENANT_EXTENSION=hindsight_api.extensions.builtin.supabase_tenant:SupabaseTenantExtension
# HINDSIGHT_API_TENANT_SUPABASE_URL=https://xxx.supabase.co
# HINDSIGHT_API_TENANT_SUPABASE_SERVICE_KEY=your-service-key
# HINDSIGHT_API_TENANT_SCHEMA_PREFIX=user
# Each user's JWT contains a "sub" claim with their UUID
# The extension derives schema: user_{uuid_with_underscores}
# All SQL is schema-qualified via fq_table()