Clerk
Clerk is a complete suite of embeddable UIs, flexible APIs, and admin dashboards to authenticate and manage users.
The Clerk Wrapper is a WebAssembly(Wasm) foreign data wrapper which allows you to read data from Clerk for use within your Postgres database.
Available Versions
Version | Wasm Package URL | Checksum |
---|---|---|
0.1.0 | https://github.com/supabase/wrappers/releases/download/wasm_clerk_fdw_v0.1.0/clerk_fdw.wasm | 613be26b59fa4c074e0b93f0db617fcd7b468d4d02edece0b1f85fdb683ebdc4 |
Preparation
Before you can query Clerk, you need to enable the Wrappers extension and store your credentials in Postgres.
Enable Wrappers
Make sure the wrappers
extension is installed on your database:
_10create extension if not exists wrappers with schema extensions;
Enable the Clerk Wrapper
Enable the Wasm foreign data wrapper:
_10create foreign data wrapper wasm_wrapper_10 handler wasm_fdw_handler_10 validator wasm_fdw_validator;
Store your credentials (optional)
By default, Postgres stores FDW credentials inside pg_catalog.pg_foreign_server
in plain text. Anyone with access to this table will be able to view these credentials. Wrappers is designed to work with Vault, which provides an additional level of security for storing credentials. We recommend using Vault to store your credentials.
_10-- Save your Clerk API key in Vault and retrieve the `key_id`_10insert into vault.secrets (name, secret)_10values (_10 'clerk',_10 '<Clerk API key>' -- Clerk API key _10)_10returning key_id;
Connecting to Clerk
We need to provide Postgres with the credentials to access Clerk and any additional options. We can do this using the create server
command:
_10create server clerk_server_10 foreign data wrapper wasm_wrapper_10 options (_10 fdw_package_url 'https://github.com/supabase/wrappers/releases/download/wasm_clerk_fdw_v0.1.0/clerk_fdw.wasm',_10 fdw_package_name 'supabase:clerk-fdw',_10 fdw_package_version '0.1.0',_10 fdw_package_checksum '613be26b59fa4c074e0b93f0db617fcd7b468d4d02edece0b1f85fdb683ebdc4',_10 api_url 'https://api.clerk.com/v1', -- optional_10 api_key_id '<key_ID>' -- The Key ID from above._10 );
Note the fdw_package_*
options are required, which specify the Wasm package metadata. You can get the available package version list from above.
Create a schema
We recommend creating a schema to hold all the foreign tables:
_10create schema if not exists clerk;
Options
The full list of foreign table options are below:
object
- Object name in Clerk, required.
Supported objects are listed below:
Object name |
---|
allowlist_identifiers |
blocklist_identifiers |
domains |
invitations |
jwt_templates |
oauth_applications |
organizations |
organization_invitations |
organization_memberships |
redirect_urls |
saml_connections |
users |
Entities
Allow-list
This is a list of all identifiers allowed to sign up to an instance.
Ref: Clerk API docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
allowlist_identifiers | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_14create foreign table clerk.allowlist_identifiers (_14 id text,_14 invitation_id text,_14 identifier text,_14 identifier_type text,_14 instance_id text,_14 created_at timestamp,_14 updated_at timestamp,_14 attrs jsonb_14)_14 server clerk_server_14 options (_14 object 'allowlist_identifiers'_14 );
Notes
- The
attrs
column contains additional attributes in JSON format
Block-list
This is a list of all identifiers which are not allowed to access an instance.
Ref: Clerk API docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
blocklist_identifiers | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_13create foreign table clerk.blocklist_identifiers (_13 id text,_13 identifier text,_13 identifier_type text,_13 instance_id text,_13 created_at timestamp,_13 updated_at timestamp,_13 attrs jsonb_13)_13 server clerk_server_13 options (_13 object 'blocklist_identifiers'_13 );
Notes
- The
attrs
column contains additional attributes in JSON format
Domains
This is a list of all domains for an instance.
Ref: Clerk API docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
domains | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_12create foreign table clerk.domains (_12 id text,_12 name text,_12 is_satellite boolean,_12 frontend_api_url text,_12 accounts_portal_url text,_12 attrs jsonb_12)_12 server clerk_server_12 options (_12 object 'domains'_12 );
Notes
- The
attrs
column contains additional attributes in JSON format
Invitations
This is a list of all non-revoked invitations for your application.
Ref: Clerk API docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
invitations | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_15create foreign table clerk.invitations (_15 id text,_15 email_address text,_15 url text,_15 revoked boolean,_15 status text,_15 expires_at timestamp,_15 created_at timestamp,_15 updated_at timestamp,_15 attrs jsonb_15)_15 server clerk_server_15 options (_15 object 'invitations'_15 );
Notes
- The
attrs
column contains additional attributes in JSON format
JWT Templates
This is a list of all JWT templates.
Ref: Clerk API docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
jwt_templates | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_15create foreign table clerk.jwt_templates (_15 id text,_15 name text,_15 lifetime bigint,_15 allowed_clock_skew bigint,_15 custom_signing_key boolean,_15 signing_algorithm text,_15 created_at timestamp,_15 updated_at timestamp,_15 attrs jsonb_15)_15 server clerk_server_15 options (_15 object 'jwt_templates'_15 );
Notes
- The
attrs
column contains additional attributes in JSON format
OAuth Applications
This is a list of OAuth applications for an instance.
Ref: Clerk API docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
oauth_applications | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_15create foreign table clerk.oauth_applications (_15 id text,_15 name text,_15 instance_id text,_15 client_id text,_15 public boolean,_15 scopes text,_15 created_at timestamp,_15 updated_at timestamp,_15 attrs jsonb_15)_15 server clerk_server_15 options (_15 object 'oauth_applications'_15 );
Notes
- The
attrs
column contains additional attributes in JSON format
Organizations
This is a list of organizations for an instance.
Ref: Clerk API docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
organizations | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_12create foreign table clerk.organizations (_12 id text,_12 name text,_12 slug text,_12 created_at timestamp,_12 updated_at timestamp,_12 attrs jsonb_12)_12 server clerk_server_12 options (_12 object 'organizations'_12 );
Notes
- The
attrs
column contains additional attributes in JSON format
Organization Invitations
This is a list of organization invitations for an instance.
Ref: Clerk API docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
organization_invitations | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_15create foreign table clerk.organization_invitations (_15 id text,_15 email_address text,_15 role text,_15 role_name text,_15 organization_id text,_15 status text,_15 created_at timestamp,_15 updated_at timestamp,_15 attrs jsonb_15)_15 server clerk_server_15 options (_15 object 'organization_invitations'_15 );
Notes
- The
attrs
column contains additional attributes in JSON format
Organization Memberships
This is a list of organization user memberships for an instance.
Ref: Clerk API docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
organization_memberships | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_12create foreign table clerk.organization_memberships (_12 id text,_12 role text,_12 role_name text,_12 created_at timestamp,_12 updated_at timestamp,_12 attrs jsonb_12)_12 server clerk_server_12 options (_12 object 'organization_memberships'_12 );
Notes
- The
attrs
column contains additional attributes in JSON format
Redirect URLs
This is a list of all whitelisted redirect urls for the instance.
Ref: Clerk API docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
redirect_urls | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_11create foreign table clerk.redirect_urls (_11 id text,_11 url text,_11 created_at timestamp,_11 updated_at timestamp,_11 attrs jsonb_11)_11 server clerk_server_11 options (_11 object 'redirect_urls'_11 );
Notes
- The
attrs
column contains additional attributes in JSON format
SAML Connections
This is a list of SAML Connections for an instance.
Ref: Clerk API docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
saml_connections | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_15create foreign table clerk.saml_connections (_15 id text,_15 name text,_15 domain text,_15 active boolean,_15 provider text,_15 user_count bigint,_15 created_at timestamp,_15 updated_at timestamp,_15 attrs jsonb_15)_15 server clerk_server_15 options (_15 object 'saml_connections'_15 );
Notes
- The
attrs
column contains additional attributes in JSON format
Users
This is a list of all users.
Ref: Clerk API docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
users | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_14create foreign table clerk.users (_14 id text,_14 external_id text,_14 username text,_14 first_name text,_14 last_name text,_14 created_at timestamp,_14 updated_at timestamp,_14 attrs jsonb_14)_14 server clerk_server_14 options (_14 object 'users'_14 );
Notes
- The
attrs
column contains additional attributes in JSON format
Query Pushdown Support
This FDW doesn't support query pushdown.
Supported Data Types
Postgres Data Type | Clerk Data Type |
---|---|
boolean | Boolean |
bigint | Number |
double precision | Number |
text | String |
timestamp | Time |
jsonb | Json |
The Clerk API uses JSON formatted data, please refer to Clerk Backend API docs for more details.
Limitations
This section describes important limitations and considerations when using this FDW:
- Large result sets may experience slower performance due to full data transfer requirement
- Query pushdown is not supported
- Materialized views using these foreign tables may fail during logical backups
Examples
Below are some examples on how to use Clerk foreign tables.
Basic example
This example will create a "foreign table" inside your Postgres database and query its data.
_17create foreign table clerk.users (_17 id text,_17 external_id text,_17 username text,_17 first_name text,_17 last_name text,_17 created_at timestamp,_17 updated_at timestamp,_17 attrs jsonb_17)_17 server clerk_server_17 options (_17 object 'users'_17 );_17_17-- query all users_17select * from clerk.users;
attrs
is a special column which stores all the object attributes in JSON format, you can extract any attributes needed from it. See more examples below.
Query JSON attributes
_10-- extract all email addresses from user_10select_10 u.id,_10 e->>'email_address' as email_10from clerk.users u_10 cross join json_array_elements((attrs->'email_addresses')::json) e;