mirror of
https://github.com/supabase/supabase.git
synced 2026-12-05 16:09:06 +00:00
## Problem The CLI reads `supabase/config.jsonc` (and `config.json`) since v3.1.0, but every docs page still shows `config.toml` only. There's also no page explaining the formats, how to switch, the `$schema` / `#:schema` declaration, or editor setup, and no reference pages for the new `supabase config convert` and `supabase config validate` commands. Linear: CLI-2871 ## Solution - **Dual-format examples from one source.** A new directive (`features/directives/ConfigFormats.ts`) picks up any ```` ```toml ```` fence with `name=supabase/config.toml` and renders it as `supabase/config.toml` / `supabase/config.jsonc` tabs. The JSONC is generated at build time with `convertCliConfigTomlToJsonc` from `@supabase/config`, the same converter `supabase config convert` uses, so authors only write TOML and the JSONC matches what the CLI would produce (comments included). Inside `<$CodeTabs>` the JSONC is added as an extra tab. - **The format choice sticks.** `ConfigCodeTabs` keeps the selected format in `localStorage`, so choosing JSONC switches every config example on the page and on later pages. - **Config reference.** The `usage` examples on `/guides/local-development/cli/config` use the same tabs (they were highlighted as Python before), and the intro mentions `config.jsonc`. The `remotes.<branch_name>` example now uses `[remotes.staging]`, since `<branch_name>` isn't a valid TOML key. - **New guide, "Config file formats"** (`/guides/local-development/cli/config-formats`): which file wins, minimum CLI version, `convert` and `validate`, schema declaration and versioning, and editor setup (VS Code trusted domains, Even Better TOML, Tombi, SchemaStore). - **CLI reference.** Adds `supabase-config-convert` and `supabase-config-validate` to the CLI reference nav. `cli_v1_commands.yaml` is the generated v3.2.0 reference, identical to the release bot's update in #53463, so the two PRs don't conflict. - **Content.** About 60 existing config examples across the guides, including the Branching configuration page, are tagged `name=supabase/config.toml`. Branching reads `config.json` and `config.jsonc` as well, and the Branching configuration page now says so. Non-Supabase TOML (`pyproject.toml`, `bunfig.toml`) and the v2-era `[inbucket]` before/after snippet stay TOML-only. - **Format-neutral prose.** Sentences that described the config as `config.toml` now say "your config file", naming `supabase/config.toml` and `supabase/config.jsonc` once per page. TOML section syntax in prose (`max_frequency` under `[auth.email]`) is written as key paths (`auth.email.max_frequency`), which read the same in both formats. Headings that named `config.toml` keep their old anchors. Sentences about what `supabase init` creates still say `config.toml`. - **Markdown export for agents.** `internals/generate-guides-markdown.ts` runs the same transform, so the `.md` pages served to AI agents include the JSONC example after each TOML one. - A test converts every tagged example under `content/`, so a broken TOML example fails tests instead of the build. New dependencies for `apps/docs`: `@supabase/config` (^1.8.0) and `effect` (the same `effect` version Studio pins). `config convert` and `config validate` ship in CLI v3.2.0, which is now stable. ## Review instructions 1. Open `/docs/guides/local-development/seeding-your-database` on the preview. Switch an example to `supabase/config.jsonc` and check the other examples on the page switch too. 2. Open `/docs/guides/local-development/cli/config` and check the usage examples open on JSONC. 3. Read `/docs/guides/local-development/cli/config-formats`. 4. Open `/docs/reference/cli/supabase-config-convert` and `/docs/reference/cli/supabase-config-validate`. ## Self-review Ran the `review-the-docs` local self-review (content, pipeline, and component checks) over the 54 changed pages. - No blockers. Fixed the nits it found: leftover TOML section syntax in prose (diff engines, declarative schemas, Branching, the common settings table on Local and hosted projects), a few long or ungrammatical sentences, and the conversion follow-up steps on Config file formats, now a list. - Links, custom anchors, nav wiring, and frontmatter check out. - The `.md` export on the preview shows each TOML example followed by its JSONC version. - `test-the-docs` deferred: the changed fences are config snippets, and `ConfigFormats.test.ts` already converts every tagged example. No procedural steps changed apart from the `config convert` and `config validate` commands on the new page. ## Checklist Check all before review: - [x] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [x] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs [style guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
135 lines
5.6 KiB
Plaintext
135 lines
5.6 KiB
Plaintext
---
|
|
id: 'auth-third-party-clerk'
|
|
title: 'Clerk third-party auth'
|
|
subtitle: 'Use Clerk with your Supabase project'
|
|
---
|
|
|
|
Clerk can be used as a third-party authentication provider alongside Supabase Auth, or standalone, with your Supabase project.
|
|
|
|
## Getting started
|
|
|
|
Getting started is incredibly easy. Start off by visiting [Clerk's Connect with Supabase page](https://dashboard.clerk.com/setup/supabase) to configure your Clerk instance for Supabase compatibility.
|
|
|
|
Finally add a [new Third-Party Auth integration with Clerk](/dashboard/project/_/auth/third-party) in the Supabase dashboard.
|
|
|
|
### Configure for local development or self-hosting
|
|
|
|
When developing locally or self-hosting with the [Supabase CLI](/docs/guides/local-development/cli/getting-started), add the following config to your config file (`supabase/config.toml` or `supabase/config.jsonc`):
|
|
|
|
```toml supabase/config.toml
|
|
[auth.third_party.clerk]
|
|
enabled = true
|
|
domain = "example.clerk.accounts.dev"
|
|
```
|
|
|
|
You will still need to configure your Clerk instance for Supabase compatibility.
|
|
|
|
### Manually configuring your Clerk instance
|
|
|
|
If you are not able to use [Clerk's Connect with Supabase page](https://dashboard.clerk.com/setup/supabase) to configure your Clerk instance for working with Supabase, follow these steps.
|
|
|
|
1. Add the `role` claim to [Clerk session tokens](https://clerk.com/docs/guides/sessions/session-tokens) by [customizing them](https://clerk.com/docs/guides/sessions/customize-session-tokens). End-users who are authenticated should have the `authenticated` value for the claim. If you have an advanced Postgres setup where authenticated end-users use different [Postgres roles](/docs/guides/database/postgres/roles) to access the database, adjust the value to use the correct role name.
|
|
2. Once all Clerk session tokens for your instance contain the `role` claim, add a [new Third-Party Auth integration with Clerk](/dashboard/project/_/auth/third-party) in the Supabase dashboard or register it in the CLI as instructed above.
|
|
|
|
## Setup the Supabase client library
|
|
|
|
<Tabs type="underlined" queryGroup="language">
|
|
|
|
<TabPanel id="ts" label="TypeScript">
|
|
|
|
<$CodeSample
|
|
path="/clerk/hooks/useSupabaseClient.ts"
|
|
lines={[[6, 14]]}
|
|
hideElidedLines={true}
|
|
/>
|
|
|
|
</TabPanel>
|
|
|
|
<$Show if="sdk:dart">
|
|
|
|
<TabPanel id="dart" label="Flutter">
|
|
|
|
```dart
|
|
import 'package:clerk_flutter/clerk_flutter.dart';
|
|
import 'package:supabase_flutter/supabase_flutter.dart';
|
|
...
|
|
|
|
await Supabase.initialize(
|
|
url: 'SUPABASE_URL',
|
|
publishableKey: 'SUPABASE_PUBLISHABLE_KEY',
|
|
accessToken: () async {
|
|
final token = await ClerkAuth.of(context).sessionToken();
|
|
return token.jwt;
|
|
},
|
|
);
|
|
```
|
|
|
|
</TabPanel>
|
|
</$Show>
|
|
|
|
<$Show if="sdk:swift">
|
|
|
|
<TabPanel id="swift" label="Swift (iOS)">
|
|
|
|
```swift
|
|
import Clerk
|
|
import Supabase
|
|
|
|
let supabase = SupabaseClient(
|
|
supabaseURL: URL(string: "https://project-ref.supabase.io")!,
|
|
supabaseKey: "supabase.publishable.key",
|
|
options: SupabaseClientOptions(
|
|
auth: SupabaseClientOptions.AuthOptions(
|
|
accessToken: {
|
|
try await Clerk.shared.session?.getToken()?.jwt
|
|
}
|
|
)
|
|
)
|
|
)
|
|
```
|
|
|
|
</TabPanel>
|
|
</$Show>
|
|
|
|
</Tabs>
|
|
|
|
## Using RLS policies
|
|
|
|
Once you've configured the Supabase client library to use Clerk session tokens, you can use RLS policies to secure access to your project's database, Storage objects and Realtime channels.
|
|
|
|
The recommended way to design RLS policies with Clerk is to use claims present in your Clerk session token to allow or reject access to your project's data. Check [Clerk's docs](https://clerk.com/docs/guides/sessions/session-tokens) on the available JWT claims and their values.
|
|
|
|
### Example: Check user organization role
|
|
|
|
<$CodeSample
|
|
path="/clerk/supabase/migrations/20250501155648_setup_database.sql"
|
|
lines={[[10, 18]]}
|
|
hideElidedLines={true}
|
|
/>
|
|
|
|
This RLS policy checks that the newly inserted row in the table has the user's declared organization ID in the `organization_id` column. Additionally it ensures that they're an `org:admin`.
|
|
|
|
This way only organization admins can add rows to the table, for organizations they're a member of.
|
|
|
|
### Example: Check user has passed second factor verification
|
|
|
|
<$CodeSample
|
|
path="/clerk/supabase/migrations/20250501155648_setup_database.sql"
|
|
lines={[[28, 35]]}
|
|
hideElidedLines={true}
|
|
/>
|
|
|
|
This example uses a restrictive RLS policy checks that the [second factor verification](https://clerk.com/docs/guides/secure/reverification) age element in the `fva` claim is not `'-1'` indicating the user has passed through second factor verification.
|
|
|
|
## Deprecated integration with JWT templates
|
|
|
|
As of 1st April 2025 the previously available [Clerk Integration with Supabase](/partners/integrations/clerk) is considered deprecated and is no longer recommended for use. All projects using the deprecated integration will be excluded from Third-Party Monthly Active User (TP-MAU) charges until at least 1st January 2026.
|
|
|
|
This integration used low-level primitives that are still available in Supabase and Clerk, such as a [configurable JWT secret](/dashboard/project/_/settings/api) and [JWT templates from Clerk](https://clerk.com/docs/guides/sessions/jwt-templates). This enables you to keep using it in an unofficial manner, though only limited support will be provided from Supabase.
|
|
|
|
Deprecation is done for the following reasons:
|
|
|
|
- Sharing your project's JWT secret with a third-party is a problematic security practice
|
|
- Rotating the project's JWT secret in this case almost always results in significant downtime for your application
|
|
- Additional latency to [generate a new JWT](https://clerk.com/docs/backend-requests/jwt-templates#generate-a-jwt) for use with Supabase, instead of using the Clerk [session tokens](https://clerk.com/docs/guides/sessions/session-tokens)
|