Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Environment:24kchengYe MemoMind Supabase

From Leeroopedia
Knowledge Sources
Domains Infrastructure, Authentication
Last Updated 2026-10-28 14:45 GMT

Overview

Supabase project for JWT-based multi-tenant authentication, enabling per-user schema isolation via Supabase Auth JWTs.

Description

This environment provides a Supabase project for JWT-based multi-tenant authentication. The `SupabaseTenantExtension` validates Supabase JWTs locally using JWKS public keys (no network call per request) and maps each authenticated user to an isolated PostgreSQL schema (`{prefix}_{user_id}`). For legacy HS256 projects, it falls back to calling the `/auth/v1/user` endpoint per request (requires service_role key). JWKS keys are cached for 10 minutes (matching Supabase Edge cache) with a minimum 30-second refresh interval.

Usage

Use this environment when deploying MemoMind with Supabase Auth for multi-tenant isolation. Each Supabase user's memories are stored in a separate PostgreSQL schema, ensuring complete data isolation. Required by the `SupabaseTenantExtension_authenticate` implementation.

System Requirements

Category Requirement Notes
OS Any (calls Supabase API) No local dependencies
Hardware Minimal JWT verification is CPU-only
Network Access to Supabase project URL For JWKS fetching and legacy HS256 fallback

Dependencies

Python Packages

  • `pyjwt` (imported as `jwt`) — JWT verification and JWKS handling
  • `httpx` — HTTP client for Supabase API calls (JWKS, legacy /auth/v1/user)
  • `hindsight_api` — TenantExtension base class

Supported JWT Algorithms

  • `RS256` — RSA asymmetric (recommended; uses JWKS local verification)
  • `ES256` — EC asymmetric (uses JWKS local verification)
  • `HS256` — Legacy symmetric (falls back to /auth/v1/user endpoint)

Credentials

The following environment variables must be set in `.env`:

  • `HINDSIGHT_API_TENANT_EXTENSION`: Must be `hindsight_api.extensions.builtin.supabase_tenant:SupabaseTenantExtension`
  • `HINDSIGHT_API_TENANT_SUPABASE_URL`: Supabase project URL (e.g., `https://your-project.supabase.co`) — required
  • `HINDSIGHT_API_TENANT_SUPABASE_SERVICE_KEY`: Supabase service_role key — required for legacy HS256 projects or health checks; optional for RS256/ES256
  • `HINDSIGHT_API_TENANT_SCHEMA_PREFIX`: Schema name prefix (default: `user`; creates `user_<uuid>` schemas)

Clients pass their Supabase JWT in the `Authorization: Bearer <jwt>` header.

Quick Install

pip install pyjwt httpx

# Configure in .env
HINDSIGHT_API_TENANT_EXTENSION=hindsight_api.extensions.builtin.supabase_tenant:SupabaseTenantExtension
HINDSIGHT_API_TENANT_SUPABASE_URL=https://your-project.supabase.co

Code Evidence

Supabase extension configuration from `supabase_tenant.py:31-38`:

HINDSIGHT_API_TENANT_EXTENSION=hindsight_api.extensions.builtin.supabase_tenant:SupabaseTenantExtension
HINDSIGHT_API_TENANT_SUPABASE_URL=https://your-project.supabase.co
HINDSIGHT_API_TENANT_SUPABASE_SERVICE_KEY=your-service-role-key
HINDSIGHT_API_TENANT_SCHEMA_PREFIX=user  # Default: "user" (creates user_<uuid> schemas)

JWKS cache configuration from `supabase_tenant.py:73-80`:

# JWKS cache TTL — Supabase Edge caches JWKS for 10 minutes, so we match that
JWKS_CACHE_TTL_SECONDS = 600
# Minimum interval between JWKS refreshes to avoid hammering the endpoint
JWKS_MIN_REFRESH_INTERVAL_SECONDS = 30
SUPPORTED_ALGORITHMS = ["RS256", "ES256"]

Required URL validation from `supabase_tenant.py:139-141`:

"HINDSIGHT_API_TENANT_SUPABASE_URL is required. "
"Set it via the HINDSIGHT_API_TENANT_SUPABASE_URL environment variable."

UUID validation for schema names from `supabase_tenant.py:83`:

_UUID_RE = re.compile(r"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$", re.IGNORECASE)

Common Errors

Error Message Cause Solution
Supabase URL not set | Set `HINDSIGHT_API_TENANT_SUPABASE_URL` in `.env`
Legacy HS256 project without service key | Set `HINDSIGHT_API_TENANT_SUPABASE_SERVICE_KEY`
Expired token or wrong algorithm | Ensure Supabase uses RS256/ES256; check token expiry
Invalid user ID format | User ID must be a valid UUID (validated by regex)

Compatibility Notes

  • RS256/ES256 (recommended): Uses JWKS local verification — no network call per request. JWKS cached for 10 minutes.
  • HS256 (legacy): Falls back to `/auth/v1/user` endpoint per request — requires service_role key and incurs network latency.
  • Schema isolation: Each user gets `{prefix}_{uuid}` schema; prefix validated as a valid PostgreSQL identifier.
  • UUID validation: Supabase user IDs are validated as UUIDs before use in schema names to prevent SQL injection.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment