Reference
Comprehensive guide to the KeyHippo PostgreSQL extension
Prerequisite You should have installed the KeyHippo extension in your Supabase PostgreSQL database.
Installation
Install the KeyHippo extension in your Supabase database:
Replace ‘0.0.33’ with the latest version number if a newer version is available.
Schemas
KeyHippo creates and uses the following schemas:
keyhippo
: Main schema for KeyHippo functions and tableskeyhippo_internal
: Internal schema for KeyHippo helper functions
Functions
Tables
KeyHippo creates and manages several tables to store API key information:
keyhippo.user_ids
: Stores user IDskeyhippo.api_key_id_owner_id
: Maps API key IDs to owner IDskeyhippo.api_key_id_name
: Stores API key names/descriptionskeyhippo.api_key_id_permission
: Stores permissions for each API keykeyhippo.api_key_id_created
: Stores creation timestamps for API keyskeyhippo.api_key_id_last_used
: Tracks the last usage of each API keykeyhippo.api_key_id_total_use
: Counts total uses of each API keykeyhippo.api_key_id_success_rate
: Tracks success rates of API key usagekeyhippo.api_key_id_total_cost
: Tracks total cost associated with each API keykeyhippo.api_key_id_revoked
: Stores revocation information for API keys
These tables are managed by KeyHippo. Direct manipulation of these tables is not recommended.
RLS Policies
KeyHippo automatically sets up Row Level Security (RLS) policies on its tables. Here’s an example of how to create a custom RLS policy that incorporates KeyHippo authentication:
This policy allows users to read their own data when authenticated either through a session token (auth.uid()
) or a valid API key (auth.keyhippo_check()
).
Vault Integration
KeyHippo uses Supabase Vault for storing sensitive information. The following secrets are automatically set up:
project_api_key_secret
: Used for API key hashingproject_jwt_secret
: Used for JWT signing in API key generation
These secrets are managed automatically by KeyHippo. Manual modification is not recommended.
Troubleshooting
Here are solutions to common issues when working with the KeyHippo extension:
For more detailed troubleshooting, refer to the KeyHippo GitHub repository or consult the full documentation.