mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## Summary Updates docs based on recent SDK changes across three of the six tracked SDKs. `supabase-py`, `supabase-kt`, and `supabase-csharp` were also analyzed this cycle but had no doc-worthy changes (internal bug fixes / dependency bumps only, or no new commits). ## Changes analyzed | SDK | Repo | Commits | Latest tag | |---|---|---|---| | js | https://github.com/supabase/supabase-js | `485695ff7...21e410f56` | v3.0.0-next.29 | | dart | https://github.com/supabase/supabase-flutter | `6979093...5447063` | yet_another_json_isolate-v2.1.1 | | py | https://github.com/supabase/supabase-py | `3c98900...0490201` | v3.0.0a1 | | swift | https://github.com/supabase/supabase-swift | `c24795d...51a083a` | v2.54.1 | | kt | https://github.com/supabase-community/supabase-kt | (no new commits) | 3.7.0 | | csharp | https://github.com/supabase-community/supabase-csharp | `572624e...ac057a2` | v1.5.0 | ## Documentation updates - **`apps/docs/content/guides/auth/sessions/pkce-flow.mdx`** — new "Overlapping flows" section documenting the experimental `appendPkceFlowIdToRedirects` option and `flowId`-aware `exchangeCodeForSession()`, added in supabase-js #2569, which fixes concurrent PKCE flows (e.g. multiple tabs) clobbering each other's stored code verifier. - **`apps/docs/spec/supabase_dart_v2.yml`** — `stream()` entry: documented the new filter methods (`like`, `ilike`, `match`, `imatch`, `isFilter`, `isDistinct`) and multi-filter chaining added in supabase-flutter #1610, plus two behavioral caveats (filter re-evaluation on UPDATE, primary-key-only DELETE payloads) and a new example. - **`apps/docs/spec/supabase_swift_v2.yml`**: - `invoke()` entry: documented the new `timeoutInterval` override on `FunctionInvokeOptions` (supabase-swift #1144), with a new example. - Added missing `generate-link` and `signOut()` (admin) spec entries — supabase-swift #1152 added these methods but Swift had no reference entries for them, even though the shared nav ids already existed in `common-client-libs-sections.json` for other SDKs. ## Test plan - [x] `python3 -c "import yaml; yaml.safe_load(...)"` on both edited YAML spec files — parses cleanly - [x] `npx prettier --check` on all three changed files — passes - [ ] Visual check of rendered reference pages for the new Swift `generate-link` / `signOut` / timeout examples and the Dart `stream()` multi-filter example (docs dev server) --- 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Documentation** - Added guidance for experimental overlapping PKCE authentication flows, including separating concurrent flows and exchanging their flow IDs. - Expanded Dart streaming documentation with filter operators, multiple-filter behavior, update semantics, delete payloads, and chained-filter examples. - Added Swift documentation for admin link generation, user sign-out, and configurable Edge Function timeouts. - Documented the default 150-second Edge Function idle timeout and per-invocation timeout overrides. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
127 lines
4.5 KiB
Plaintext
127 lines
4.5 KiB
Plaintext
---
|
|
title: 'PKCE flow'
|
|
subtitle: 'About authenticating with PKCE flow.'
|
|
---
|
|
|
|
The Proof Key for Code Exchange (PKCE) flow is one of two ways that a user can authenticate and your app can receive the necessary access and refresh tokens.
|
|
|
|
The flow is an implementation detail handled for you by Supabase Auth, but understanding the difference between PKCE and [implicit flow](/docs/guides/auth/sessions/implicit-flow) is important for understanding the difference between client-only and server-side auth.
|
|
|
|
## How it works
|
|
|
|
After a successful verification, the user is redirected to your app with a URL that looks like this:
|
|
|
|
```
|
|
https://yourapp.com/...?code=<...>
|
|
```
|
|
|
|
The `code` parameter is commonly known as the Auth Code and can be exchanged for an access token by calling `exchangeCodeForSession(code)`.
|
|
|
|
<Admonition type="note">
|
|
|
|
For security purposes, the code has a validity of 5 minutes and can only be exchanged for an access token once. You will need to restart the authentication flow from scratch if you wish to obtain a new access token.
|
|
|
|
</Admonition>
|
|
|
|
As the flow is run server side, `localStorage` may not be available. You may configure the client library to use a custom storage adapter and an alternate backing storage such as cookies by setting the `storage` option to an object with the following methods:
|
|
|
|
```js
|
|
import { type SupportedStorage } from '@supabase/supabase-js';
|
|
const supportsLocalStorage = () => true
|
|
|
|
// ---cut---
|
|
const customStorageAdapter: SupportedStorage = {
|
|
getItem: (key) => {
|
|
if (!supportsLocalStorage()) {
|
|
// Configure alternate storage
|
|
return null
|
|
}
|
|
return globalThis.localStorage.getItem(key)
|
|
},
|
|
setItem: (key, value) => {
|
|
if (!supportsLocalStorage()) {
|
|
// Configure alternate storage here
|
|
return
|
|
}
|
|
globalThis.localStorage.setItem(key, value)
|
|
},
|
|
removeItem: (key) => {
|
|
if (!supportsLocalStorage()) {
|
|
// Configure alternate storage here
|
|
return
|
|
}
|
|
globalThis.localStorage.removeItem(key)
|
|
},
|
|
}
|
|
```
|
|
|
|
You may also configure the client library to automatically exchange it for a session after a successful redirect. This can be done by setting the `detectSessionInUrl` option to `true`.
|
|
|
|
Putting it all together, your client library initialization may look like this:
|
|
|
|
```js
|
|
import { createClient } from '@supabase/supabase-js'
|
|
|
|
// ---cut---
|
|
const supabase = createClient('https://your-project-id.supabase.co', 'sb_publishable_...', {
|
|
// ...
|
|
auth: {
|
|
// ...
|
|
detectSessionInUrl: true,
|
|
flowType: 'pkce',
|
|
storage: {
|
|
getItem: () => Promise.resolve('FETCHED_TOKEN'),
|
|
setItem: () => {},
|
|
removeItem: () => {},
|
|
},
|
|
},
|
|
// ...
|
|
})
|
|
```
|
|
|
|
## Limitations
|
|
|
|
Behind the scenes, the code exchange requires a code verifier. Both the code in the URL and the code verifier are sent back to the Auth server for a successful exchange.
|
|
|
|
The code verifier is created and stored locally when the Auth flow is first initiated. That means the code exchange must be initiated on the same browser and device where the flow was started.
|
|
|
|
## Overlapping flows
|
|
|
|
If more than one PKCE flow is started on the same browser before either one completes (for example, `signInWithOAuth()` called in two tabs), the code verifier stored for the earlier flow is overwritten by the later one, and exchanging the first flow's code fails.
|
|
|
|
<Admonition type="caution" title="Experimental">
|
|
|
|
Support for overlapping flows is currently experimental and requires explicit opt-in as the API may change without notice.
|
|
|
|
</Admonition>
|
|
|
|
To keep each flow's verifier separate, set the `appendPkceFlowIdToRedirects` option when creating the client:
|
|
|
|
```js
|
|
const supabase = createClient(supabaseUrl, supabaseKey, {
|
|
auth: {
|
|
experimental: { appendPkceFlowIdToRedirects: true },
|
|
},
|
|
})
|
|
```
|
|
|
|
With this enabled, the client library appends a `sb_flow_id` query parameter to `redirectTo`, so your OAuth callback page can read it back and use it to select the matching verifier. You can also get the flow ID directly from the response of `signInWithOAuth()`:
|
|
|
|
```js
|
|
const { data, error } = await supabase.auth.signInWithOAuth({
|
|
provider: 'github',
|
|
})
|
|
|
|
const flowId = data.flowId
|
|
```
|
|
|
|
Pass the flow ID to `exchangeCodeForSession()` to make sure the correct verifier is used, whether you read it from `data.flowId` or from the `sb_flow_id` query parameter in the redirect URL:
|
|
|
|
```js
|
|
const { data, error } = await supabase.auth.exchangeCodeForSession(authCode, { flowId })
|
|
```
|
|
|
|
## Resources
|
|
|
|
- [OAuth 2.0 guide](https://oauth.net/2/pkce/) to PKCE flow
|