mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +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)
185 lines
5.8 KiB
Plaintext
185 lines
5.8 KiB
Plaintext
---
|
|
id: 'auth-third-party-aws-cognito'
|
|
title: 'Amazon Cognito (Amplify)'
|
|
subtitle: 'Use Amazon Cognito via Amplify or standalone with your Supabase project'
|
|
---
|
|
|
|
Amazon Cognito User Pools (via AWS Amplify or on its own) can be used as a third-party authentication provider alongside Supabase Auth, or standalone, with your Supabase project.
|
|
|
|
## Getting started
|
|
|
|
1. First you need to add an integration to connect your Supabase project with your Amazon Cognito User Pool. You will need the pool's ID and region.
|
|
2. Add a new Third-party Auth integration in your project's [Authentication settings](/dashboard/project/_/auth/third-party) or configure it in the CLI.
|
|
3. Assign the `role: 'authenticated'` custom claim to all JWTs by using a Pre-Token Generation Trigger.
|
|
4. Finally setup the [Supabase client](/docs/reference/javascript/introduction) in your application.
|
|
|
|
## Setup the Supabase client library
|
|
|
|
<Tabs type="underlined" queryGroup="cognito-create-client">
|
|
|
|
<TabPanel id="ts" label="TypeScript (Amplify)">
|
|
|
|
```typescript
|
|
import { fetchAuthSession, Hub } from 'aws-amplify/auth'
|
|
|
|
const supabase = createClient(
|
|
'https://<supabase-project>.supabase.co',
|
|
'SUPABASE_PUBLISHABLE_KEY',
|
|
{
|
|
accessToken: async () => {
|
|
const tokens = await fetchAuthSession()
|
|
|
|
// Alternatively you can use tokens?.idToken instead.
|
|
return tokens?.accessToken
|
|
},
|
|
}
|
|
)
|
|
|
|
// if you're using Realtime you also need to set up a listener for Cognito auth changes
|
|
Hub.listen('auth', () => {
|
|
fetchAuthSession().then((tokens) => supabase.realtime.setAuth(tokens?.accessToken))
|
|
})
|
|
```
|
|
|
|
</TabPanel>
|
|
|
|
<$Show if="sdk:swift">
|
|
|
|
<TabPanel id="swift" label="Swift (iOS)">
|
|
|
|
```swift
|
|
import Supabase
|
|
import AWSPluginsCore
|
|
|
|
struct UnexpectedAuthSessionError: Error {}
|
|
|
|
let supabase = SupabaseClient(
|
|
supabaseURL: URL(string: "https://<supabase-project>.supabase.co")!,
|
|
supabaseKey: "SUPABASE_PUBLISHABLE_KEY",
|
|
options: SupabaseClientOptions(
|
|
auth: SupabaseClientOptions.AuthOptions(
|
|
accessToken: {
|
|
let session = try await Amplify.Auth.fetchAuthSession()
|
|
|
|
guard let cognitoTokenProvider = session as? AuthCognitoTokensProvider else {
|
|
throw UnexpectedAuthSessionError()
|
|
}
|
|
|
|
let tokens = try cognitoTokenProvider.getCognitoTokens().get()
|
|
return tokens.idToken
|
|
}
|
|
)
|
|
)
|
|
)
|
|
```
|
|
|
|
</TabPanel>
|
|
</$Show>
|
|
|
|
<$Show if="sdk:dart">
|
|
|
|
<TabPanel id="dart" label="Flutter">
|
|
|
|
```dart
|
|
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
|
|
import 'package:amplify_flutter/amplify_flutter.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:supabase_flutter/supabase_flutter.dart';
|
|
|
|
Future<void> main() async {
|
|
await Supabase.initialize(
|
|
url: 'https://<supabase-project>.supabase.co',
|
|
publishableKey: 'SUPABASE_PUBLISHABLE_KEY',
|
|
accessToken: () async {
|
|
final session = await Amplify.Auth.fetchAuthSession();
|
|
final cognitoSession = session as CognitoAuthSession;
|
|
return cognitoSession.userPoolTokensResult.value.accessToken.raw;
|
|
},
|
|
);
|
|
runApp(const MyApp());
|
|
}
|
|
```
|
|
|
|
</TabPanel>
|
|
</$Show>
|
|
|
|
<$Show if="sdk:kotlin">
|
|
|
|
<TabPanel id="kotlin" label="Kotlin">
|
|
|
|
```kotlin
|
|
import com.amplifyframework.auth.AuthSession
|
|
import com.amplifyframework.auth.cognito.AWSCognitoAuthSession
|
|
import com.amplifyframework.core.Amplify
|
|
|
|
val supabase = createSupabaseClient(
|
|
"https://<supabase-project>.supabase.co",
|
|
"SUPABASE_PUBLISHABLE_KEY"
|
|
) {
|
|
accessToken = {
|
|
getAccessToken()
|
|
}
|
|
}
|
|
|
|
suspend fun getAccessToken(): String? {
|
|
return suspendCoroutine {
|
|
Amplify.Auth.fetchAuthSession(
|
|
{ result: AuthSession ->
|
|
val cognitoAuthSession = result as AWSCognitoAuthSession
|
|
it.resume(cognitoAuthSession.userPoolTokensResult.value?.accessToken)
|
|
},
|
|
{ _ ->
|
|
// Handle error
|
|
})
|
|
}
|
|
}
|
|
```
|
|
|
|
</TabPanel>
|
|
</$Show>
|
|
|
|
</Tabs>
|
|
|
|
## Add a new Third-Party Auth integration to your project
|
|
|
|
In the dashboard navigate to your project's [Authentication settings](/dashboard/project/_/auth/third-party) and find the Third-Party Auth section to add a new integration.
|
|
|
|
In the CLI add the following config to your config file (`supabase/config.toml` or `supabase/config.jsonc`):
|
|
|
|
```toml supabase/config.toml
|
|
[auth.third_party.aws_cognito]
|
|
enabled = true
|
|
user_pool_id = "<id>"
|
|
user_pool_region = "<region>"
|
|
```
|
|
|
|
## Use a pre-token generation trigger to assign the authenticated role
|
|
|
|
Your Supabase project inspects the `role` claim present in all JWTs sent to it, to assign the correct [Postgres role](/docs/guides/database/postgres/roles) when using the Data API, Storage or Realtime authorization.
|
|
|
|
By default, Amazon Cognito JWTs (both ID token and access tokens) do not contain a `role` claim in them. If you were to send such a JWT to your Supabase project, the `anon` role would be assigned when executing the Postgres query. Most of your app's logic will be accessible by the `authenticated` role.
|
|
|
|
A recommended approach to do this is to configure a [Pre-Token Generation Trigger](https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-pre-token-generation.html) either `V1_0` (ID token only) or `V2_0` (both access and ID token). To do this you will need to create a new Lambda function (in any language and runtime) and assign it to the [Amazon Cognito User Pool's Lambda Triggers configuration](https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-identity-pools-working-with-aws-lambda-triggers.html). For example, the Lambda function should look similar to this:
|
|
|
|
<Tabs type="underlined" queryGroup="cognito-lambda">
|
|
|
|
<TabPanel id="blocking-nodejs" label="Node.js">
|
|
|
|
```javascript
|
|
export const handler = async (event) => {
|
|
event.response = {
|
|
claimsOverrideDetails: {
|
|
claimsToAddOrOverride: {
|
|
role: 'authenticated',
|
|
},
|
|
},
|
|
}
|
|
|
|
return event
|
|
}
|
|
```
|
|
|
|
</TabPanel>
|
|
|
|
</Tabs>
|