Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Add identity linking methods to Kotlin docs (#19744)

Jan Tennertd59f44678a4a
diff --git a/apps/docs/pages/guides/auth/auth-identity-linking.mdx b/apps/docs/pages/guides/auth/auth-identity-linking.mdx
index cbb6352748d..d564dba6e20 100644
--- a/apps/docs/pages/guides/auth/auth-identity-linking.mdx
+++ b/apps/docs/pages/guides/auth/auth-identity-linking.mdx
@@ -41,16 +41,45 @@ Users that signed up with [SAML SSO](/docs/guides/auth/sso/auth-sso-saml) will n
### 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 logged in. To link an OAuth identity to the user, call [`linkIdentity()`](/docs/reference/javascript/auth-linkidentity):
```js
const { data, error } = await supabase.auth.linkIdentity({ provider: 'google' })
```
+</TabPanel>
+<TabPanel id="kotlin" label="Kotlin">
+
+Supabase Auth allows a user to initiate identity linking with a different email address when they are logged in. To link an OAuth identity to the user, call [`linkIdentity()`](/docs/reference/kotlin/auth-linkidentity):
+
+```kotlin
+supabase.auth.linkIdentity(Google)
+```
+</TabPanel>
+</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/_/settings/auth).
## 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 logged in and have at least 2 linked identities in order to unlink an existing identity.
```js
@@ -66,6 +95,24 @@ const googleIdentity = identities.find((identity) => identity.provider === 'goog
const { data, error } = await supabase.auth.unlinkIdentity(googleIdentity)
```
+</TabPanel>
+<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 logged 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>
+</Tabs>
+
export const Page = ({ children }) => <Layout meta={meta} children={children} />
export default Page
diff --git a/spec/supabase_kt_v2.yml b/spec/supabase_kt_v2.yml
index bb1cbbbe30a..7205daaae97 100644
--- a/spec/supabase_kt_v2.yml
+++ b/spec/supabase_kt_v2.yml
@@ -2770,6 +2770,64 @@ functions:
}
}
```
+ - id: get-user-identities
+ title: 'currentIdentitiesOrNull()'
+ $ref: '@supabase/gotrue-js.GoTrueClient.getUserIdentities'
+ notes: |
+ - The user needs to be signed in to call `currentIdentitiesOrNull()`.
+ examples:
+ - id: get-user-identities
+ name: Returns a list of identities linked to the user
+ isSpotlight: true
+ code: |
+ ```kotlin
+ //get the identities from the current user
+ val identities = supabase.auth.currentIdentitiesOrNull()
+ //Or retrieve them
+ val identities = supabase.auth.retrieveUserForCurrentSession().identities
+ ```
+ - id: link-identity
+ title: 'linkIdentity()'
+ $ref: '@supabase/gotrue-js.GoTrueClient.linkIdentity'
+ notes: |
+ - The **Enable Manual Linking** option must be enabled from your [project's authentication settings](/dashboard/project/_/settings/auth).
+ - The user needs to be signed in to call `linkIdentity()`.
+ - If the candidate identity is already linked to the existing user or another user, `linkIdentity()` will fail.
+ - This method works similarly to `signInWith()` using an OAuthProvider. To learn how to handle OTP links & OAuth refer to [initializing](/docs/reference/kotlin/initializing)
+ examples:
+ - id: link-identity
+ name: Link an identity to a user
+ isSpotlight: true
+ code: |
+ ```kotlin
+ supabase.auth.linkIdentity(OAuthProvider)
+
+ //Example:
+ supabase.auth.linkIdentity(Google)
+ ```
+ - id: unlink-identity
+ title: 'unlinkIdentity()'
+ $ref: '@supabase/gotrue-js.GoTrueClient.unlinkIdentity'
+ notes: |
+ - The **Enable Manual Linking** option must be enabled from your [project's authentication settings](/dashboard/project/_/settings/auth).
+ - The user needs to be signed in to call `unlinkIdentity()`.
+ - The user must have at least 2 identities in order to unlink an identity.
+ - The identity to be unlinked must belong to the user.
+ examples:
+ - id: unlink-identity
+ name: Unlink an identity
+ isSpotlight: true
+ code: |
+ ```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!!)
+ ```
- id: set-session
title: 'importSession()'
$ref: '@supabase/gotrue-js.GoTrueClient.setSession'