Files
supabase/apps/docs/content/guides/auth/auth-identity-linking.mdx
Miranda Limonczenko b66bedd1c9 docs(guides): rework five explainer pages to the explainer template (#53755)
## Problem

Five concept pages are close to the explainer template from #53751 but
don't follow it. They have no value statement and no Related resources,
and they have style gaps such as missing descriptions, topic-name alt
text, and a diagram with no accessibility title or description.

Part of DOCS-1617. A second batch of five pages is in #53757.

## Solution

The PR is one squashed commit. It covers a style pass, the restructure
to the template, critic-pass fixes, tables and lists, the opener change,
and content moved in from other pages.

### Structure

| Page | Change |
| --- | --- |
| `auth/architecture` | Value statement, a `## Layers` table from the
numbered list, Related resources |
| `storage/cdn/fundamentals` | Value statement, `## Example` renamed to
`## How caching works`, Related resources |
| `storage/schema/design` | Retitled `Storage schema`, value statement,
`## Tables` heading, the tables paragraph as a table, Related resources
|
| `storage/security/ownership` | Retitled `Storage ownership` with the
sidebar label `Ownership`, value statement, the deprecated `owner` note
moved into body text, Related resources |
| `auth/identities` | Retitled `Auth identities`, value statement,
Related resources |

- **Linked headings**: headings that other pages link to keep their
text: `#client-layer`, `#auth-service`, `#postgres`,
`#public-vs-private-buckets`, and `#the-user-identity-object`.
- **Openers and tables**: only the value statement and a cross-reference
come before the first heading, and each concept opener moves into the
first H2, per the template change in #53751. Prose comparisons and
parallel facts become tables and lists. On Storage CDN, the cache steps
are a numbered list, and a library analogy follows them.
- **Moved content**: each explainer now owns its concept, and the how-to
that held it links back. Nothing is newly written; every added fact
comes from an existing page:
- Identities: `## How Auth links identities` and `## Limits`, moved from
the Automatic linking section and SAML note in [Identity
linking](/docs/guides/auth/auth-identity-linking), which now links back.
- Storage ownership: who owns a copied or moved object, from [Copy
objects](/docs/guides/storage/management/copy-move-objects), which links
back.
- Auth architecture: `## Limits`, the Auth server's single region, from
[JWTs](/docs/guides/auth/jwts#verifying-a-jwt-from-supabase), which now
keeps only its advice and links back.
- Storage CDN: the extra statuses that count as hits, from [Cache
metrics](/docs/guides/storage/cdn/metrics), which links back.
- **Facts**: unchanged. The value statements, Related resources, and the
CDN analogy are the only new text. Tables, lists, and moved content
restate facts already in the docs.

### Style
- **Descriptions**: add or rewrite one per page, 150 to 160 characters.
- **Alt text**: rewrite against the images. The Auth architecture
diagram now names each route and service, and the two CDN images
describe the cache miss and cache hit.
- **Diagram**: add `accTitle` and `accDescr` to the Storage schema
diagram.
- **Admonitions**: lead with their impact, and cut one that restated the
body text on Auth architecture.
- **Terms**: `WORD_LIST.md` passes for _we_, _will_, _since_, _auto-_,
_ID_, numbers, and spelled-out RLS. External links name their
destination.
- **Subtitles**: cut two that repeated the title or description.

The critic-pass fixes come from a clean-context critic pass against the
style guide.

Facts are unchanged. Skipped on purpose:

- The CDN page's two PNG sequence diagrams aren't converted to Mermaid,
because that's new content.
- `Public vs private buckets` keeps `vs`, because other pages link to
that heading.

### Structure numbers

These numbers are from before the opener and table changes.

| Page | Chars before → after | Headings | Generic headings |
Description chars |
| --- | --- | --- | --- | --- |
| `auth/architecture` | 3,437 → 4,839 | 3 → 5 | 0 → 0 | 0 → 159 |
| `storage/cdn/fundamentals` | 2,617 → 3,632 | 2 → 3 | 1 → 0 | 53 → 152
|
| `storage/schema/design` | 2,819 → 3,875 | 1 → 3 | 0 → 0 | 30 → 154 |
| `storage/security/ownership` | 1,628 → 2,006 | 1 → 2 | 0 → 0 | 71 →
155 |
| `auth/identities` | 3,315 → 4,087 | 1 → 2 | 0 → 0 | 0 → 159 |

Characters grow mostly from descriptions, longer alt text, table
padding, and Related resources. Search top-k isn't recorded, because
there's no fixed query set yet.

### How the template did

- **Fit without changes**: the value statement with a how-to link,
Related resources, the `How <concept> works` Process slot, and the
diagram accessibility rule. The rule caught a real gap on Storage
schema.
- **Fit after a fix in #53751**: the concept heading, one H2 per part,
linked headings in a slot, principles, and the repeated how-to link. See
the learnings in #53751.
- **Still loose**: `auth/architecture` has no concept paragraph of its
own, because the layers are the concept. `storage/security/ownership`
has an `## Access control` section that fits no slot, which is a
principle plus one SQL example.

### Preview

| Page | Live | Preview |
| --- | --- | --- |
| Auth architecture |
[Live](https://supabase.com/docs/guides/auth/architecture) |
[Preview](https://docs-git-docs-explainer-rework-supabase.vercel.app/docs/guides/auth/architecture)
|
| Storage CDN |
[Live](https://supabase.com/docs/guides/storage/cdn/fundamentals) |
[Preview](https://docs-git-docs-explainer-rework-supabase.vercel.app/docs/guides/storage/cdn/fundamentals)
|
| Storage schema |
[Live](https://supabase.com/docs/guides/storage/schema/design) |
[Preview](https://docs-git-docs-explainer-rework-supabase.vercel.app/docs/guides/storage/schema/design)
|
| Storage ownership |
[Live](https://supabase.com/docs/guides/storage/security/ownership) |
[Preview](https://docs-git-docs-explainer-rework-supabase.vercel.app/docs/guides/storage/security/ownership)
|
| Identities | [Live](https://supabase.com/docs/guides/auth/identities)
|
[Preview](https://docs-git-docs-explainer-rework-supabase.vercel.app/docs/guides/auth/identities)
|

## Review instructions

1. Open each page's live and preview links from the Preview table side
by side.
2. Check that each page opens with a value statement and ends with
Related resources.
3. Open `/docs/guides/auth/architecture#client-layer` and
`/docs/guides/storage/cdn/fundamentals#public-vs-private-buckets` on the
preview, and check that each jumps to its heading.
4. On Auth architecture and Storage CDN, compare the new alt text with
the images in `apps/docs/public/img`.
5. On Storage schema, check that the diagram renders and that the tables
table matches it.

## 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)
2026-11-23 16:18:11 -08:00

302 lines
11 KiB
Plaintext

---
id: 'auth-identity-linking'
title: 'Identity Linking'
description: 'Manage the identities associated with your user'
subtitle: 'Manage the identities associated with your user'
---
## Identity linking strategies
Currently, Supabase Auth supports 2 strategies to link an identity to a user:
1. [Automatic Linking](#automatic-linking)
2. [Manual Linking](#manual-linking-beta)
<Admonition type="note" title="No identity linking for SSO accounts">
Users who signed up with SAML SSO can't be linked, automatically or manually. For details, see [Identity limits](/docs/guides/auth/identities#limits).
</Admonition>
### Automatic linking
Supabase Auth automatically links identities with the same email address to a single user. For how it finds the user and which identities it removes, see [How Auth links identities](/docs/guides/auth/identities#how-auth-links-identities).
### Manual linking (beta)
<Tabs
scrollable
size="small"
type="underlined"
defaultActiveId="js"
queryGroup="language"
>
<TabPanel id="js" label="JavaScript">
Supabase Auth allows a user to initiate identity linking with a different email address when they are signed in. To link an OAuth identity to the user, call [`linkIdentity()`](/docs/reference/javascript/auth-linkidentity):
```js
import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://your-project-id.supabase.co', 'sb_publishable_...')
// ---cut---
const { data, error } = await supabase.auth.linkIdentity({ provider: 'google' })
```
</TabPanel>
<$Show if="sdk:dart">
<TabPanel id="dart" label="Dart">
Supabase Auth allows a user to initiate identity linking with a different email address when they are signed in. To link an OAuth identity to the user, call [`linkIdentity()`](/docs/reference/dart/auth-linkidentity):
```dart
await supabase.auth.linkIdentity(OAuthProvider.google);
```
</TabPanel>
</$Show>
<$Show if="sdk:swift">
<TabPanel id="swift" label="Swift">
Supabase Auth allows a user to initiate identity linking with a different email address when they are signed in. To link an OAuth identity to the user, call [`linkIdentity()`](/docs/reference/swift/auth-linkidentity):
```swift
try await supabase.auth.linkIdentity(provider: .google)
```
</TabPanel>
</$Show>
<$Show if="sdk:kotlin">
<TabPanel id="kotlin" label="Kotlin">
Supabase Auth allows a user to initiate identity linking with a different email address when they are signed in. To link an OAuth identity to the user, call [`linkIdentity()`](/docs/reference/kotlin/auth-linkidentity):
```kotlin
supabase.auth.linkIdentity(Google)
```
</TabPanel>
</$Show>
<$Show if="sdk:python">
<TabPanel id="python" label="Python">
Supabase Auth allows a user to initiate identity linking with a different email address when they are signed in. To link an OAuth identity to the user, call [`link_identity()`](/docs/reference/python/auth-linkidentity):
```python
response = supabase.auth.link_identity({'provider': 'google'})
```
</TabPanel>
</$Show>
<$Show if="sdk:csharp">
<TabPanel id="csharp" label="C#">
Supabase Auth allows a user to initiate identity linking with a different email address when they are signed in. To link an OAuth identity to the user, call [`LinkIdentity()`](/docs/reference/csharp/auth-linkidentity):
```c#
var state = await supabase.Auth.LinkIdentity(Provider.Google, new SignInOptions { FlowType = OAuthFlowType.PKCE });
var authorizeUrl = state.Uri;
```
</TabPanel>
</$Show>
</Tabs>
In the example above, the user will be redirected to Google to complete the OAuth2.0 flow. Once the OAuth2.0 flow has completed successfully, the user will be redirected back to the application and the Google identity will be linked to the user. You can enable manual linking from your project's authentication [configuration options](/dashboard/project/_/auth/providers) or by setting the environment variable `GOTRUE_SECURITY_MANUAL_LINKING_ENABLED: true` when self-hosting.
### Link identity with native OAuth (ID token)
<Tabs
scrollable
size="small"
type="underlined"
defaultActiveId="js"
queryGroup="language"
>
<TabPanel id="js" label="JavaScript">
For native mobile applications, you can link an identity using an ID token obtained from a third-party OAuth provider. This is useful when you want to use native OAuth flows (like Google Sign-In or [Sign in with Apple](/docs/guides/auth/social-sign-in/auth-apple)) rather than web-based OAuth redirects.
```js
// Example with Google Sign-In (using a native Google Sign-In library)
const idToken = 'ID_TOKEN_FROM_GOOGLE'
const accessToken = 'ACCESS_TOKEN_FROM_GOOGLE'
const { data, error } = await supabase.auth.linkIdentity({
provider: 'google',
token: idToken,
access_token: accessToken,
})
```
</TabPanel>
<$Show if="sdk:dart">
<TabPanel id="dart" label="Dart">
For Flutter applications, you can link an identity using an ID token obtained from native OAuth packages like `google_sign_in` or `sign_in_with_apple`. Call [`linkIdentityWithIdToken()`](/docs/reference/dart/auth-linkidentitywithidtoken):
```dart
import 'package:google_sign_in/google_sign_in.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
// First, obtain the ID token from the native provider
final GoogleSignIn googleSignIn = GoogleSignIn(
clientId: iosClientId,
serverClientId: webClientId,
);
final googleUser = await googleSignIn.signIn();
final googleAuth = await googleUser!.authentication;
// Link the Google identity to the current user
final response = await supabase.auth.linkIdentityWithIdToken(
provider: OAuthProvider.google,
idToken: googleAuth.idToken!,
accessToken: googleAuth.accessToken!,
);
```
This method supports the same OAuth providers as `signInWithIdToken()`: Google, Apple, Facebook, Kakao, and Keycloak.
</TabPanel>
</$Show>
</Tabs>
## Unlink an identity
<Tabs
scrollable
size="small"
type="underlined"
defaultActiveId="js"
queryGroup="language"
>
<TabPanel id="js" label="JavaScript">
You can use [`getUserIdentities()`](/docs/reference/javascript/auth-getuseridentities) to fetch all the identities linked to a user. Then, call [`unlinkIdentity()`](/docs/reference/javascript/auth-unlinkidentity) to unlink the identity. The user needs to be signed in and have at least 2 linked identities in order to unlink an existing identity.
```js
import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://your-project-id.supabase.co', 'sb_publishable_...')
// ---cut---
// retrieve all identities linked to a user
const { data: identities, error: identitiesError } = await supabase.auth.getUserIdentities()
if (!identitiesError) {
// find the google identity linked to the user
const googleIdentity = identities.identities.find((identity) => identity.provider === 'google')
if (googleIdentity) {
// unlink the google identity from the user
const { data, error } = await supabase.auth.unlinkIdentity(googleIdentity)
}
}
```
</TabPanel>
<$Show if="sdk:dart">
<TabPanel id="dart" label="Dart">
You can use [`getUserIdentities()`](/docs/reference/dart/auth-getuseridentities) to fetch all the identities linked to a user. Then, call [`unlinkIdentity()`](/docs/reference/dart/auth-unlinkidentity) to unlink the identity. The user needs to be signed in and have at least 2 linked identities in order to unlink an existing identity.
```dart
// retrieve all identities linked to a user
final List<UserIdentity> identities = await supabase.auth.getUserIdentities();
// find the google identity linked to the user
final UserIdentity googleIdentity =
identities.singleWhere((identity) => identity.provider == 'google');
// unlink the google identity from the user
await supabase.auth.unlinkIdentity(googleIdentity);
```
</TabPanel>
</$Show>
<$Show if="sdk:swift">
<TabPanel id="swift" label="Swift">
You can use [`getUserIdentities()`](/docs/reference/swift/auth-getuseridentities) to fetch all the identities linked to a user. Then, call [`unlinkIdentity()`](/docs/reference/swift/auth-unlinkidentity) to unlink the identity. The user needs to be signed in and have at least 2 linked identities in order to unlink an existing identity.
```swift
// retrieve all identities linked to a user
let identities = try await supabase.auth.userIdentities()
// find the google identity linked to the user
let googleIdentity = identities.first { $0.provider == .google }
// unlink the google identity from the user
try await supabase.auth.unlinkIdentity(googleIdentity)
```
</TabPanel>
</$Show>
<$Show if="sdk:kotlin">
<TabPanel id="kotlin" label="Kotlin">
You can use [`currentIdentitiesOrNull()`](/docs/reference/kotlin/auth-getuseridentities) to get all the identities linked to a user. Then, call [`unlinkIdentity()`](/docs/reference/kotlin/auth-unlinkidentity) to unlink the identity. The user needs to be signed in and have at least 2 linked identities in order to unlink an existing identity.
```kotlin
//get all identities linked to a user
val identities = supabase.auth.currentIdentitiesOrNull() ?: emptyList()
//find the google identity linked to the user
val googleIdentity = identities.first { it.provider == "google" }
//unlink the google identity from the user
supabase.auth.unlinkIdentity(googleIdentity.identityId!!)
```
</TabPanel>
</$Show>
<$Show if="sdk:python">
<TabPanel id="python" label="Python">
You can use [`get_user_identities()`](/docs/reference/python/auth-getuseridentities) to fetch all the identities linked to a user. Then, call [`unlink_identity()`](/docs/reference/python/auth-unlinkidentity) to unlink the identity. The user needs to be signed in and have at least 2 linked identities in order to unlink an existing identity.
```python
# retrieve all identities linked to a user
response = supabase.auth.get_user_identities()
# find the google identity linked to the user
google_identity = next((identity for identity in response.identities if identity.provider == 'google'), None)
# unlink the google identity from the user
if google_identity:
response = supabase.auth.unlink_identity(google_identity.identity_id)
```
</TabPanel>
</$Show>
<$Show if="sdk:csharp">
<TabPanel id="csharp" label="C#">
Use `CurrentUser.Identities` to get all the identities linked to a user. Then, call [`UnlinkIdentity()`](/docs/reference/csharp/auth-unlinkidentity) to unlink the identity. The user needs to be signed in and have at least 2 linked identities in order to unlink an existing identity.
```c#
// get all identities linked to the user
var identities = supabase.Auth.CurrentUser.Identities;
// find the google identity linked to the user
var googleIdentity = identities.First(x => x.Provider == "google");
// unlink the google identity from the user
await supabase.Auth.UnlinkIdentity(googleIdentity);
```
</TabPanel>
</$Show>
</Tabs>
## Frequently asked questions
### How to add email/password sign-in to an OAuth account?
Call the `updateUser({ password: 'validpassword'})` to add email with password authentication to an account created with an OAuth provider (Google, GitHub, etc.).
### Can you sign up with email if already using OAuth?
If you try to create an email account after previously signing up with OAuth using the same email, you'll receive an obfuscated user response with no verification email sent. This prevents user enumeration attacks.