Skip to content

Commit

Permalink
feat: Added basic instructions to the doc
Browse files Browse the repository at this point in the history
  • Loading branch information
royanger committed Dec 18, 2024
1 parent 2938bb9 commit c2d6fff
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions docs/custom-flows/manage-oauth-accounts.mdx
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
---
title: Build a custom flow for managing external accounts
description: Learn how to use the Clerk API to build a custom flow for adding and managing OAuth accounts
title: Build a custom flow for managing SSO connections
description: Learn how to use the Clerk API to build a custom flow for adding and managing SSO connections
---

<Steps>

## Enable one or more SSO connections

For your users to be able to add or manage OAuth connections, you will ned to enable one or more SSO connections.

1. In the Clerk Dashboard, navigate to the [SSO connections](https://dashboard.clerk.com/last-active?path=user-authentication/sso-connections) page.
1. Ensure there is at least one enabled SSO connections.
1. Use the `Add connections` button to enable SSO connections.

## Edit the `options` array

1. Edit the `options` array in the code below to add all of your enabled SSO connections.
1. The `OAuthStrategy` lists all of the strategies for the pre-configured SSO connections.
1. Custom SSO connections will use a strategy like `oauth_custom_<name>`. The `OAuthStrategy` type includes typing for custom providers. The code example below will need modifying to support custom providers.

</Steps>

```tsx {{ filename: 'app/account/manage-external-accounts/page.tsx', collapsible: true }}
'use client'

import { UserButton, useUser } from '@clerk/nextjs'
import { OAuthStrategy } from '@clerk/types'
import { useRouter } from 'next/navigation'

const capitalizeProvider = (provider: string) => {
const capitalize = (provider: string) => {
return `${provider.slice(0, 1).toUpperCase()}${provider.slice(1)}`
}

Expand All @@ -22,7 +40,7 @@ export default function AddAccount() {
const options: OAuthStrategy[] = ['oauth_discord', 'oauth_google', 'oauth_github']

// handle adding the new external account
const addOAuth = async (strategy: OAuthStrategy) => {
const addSSO = async (strategy: OAuthStrategy) => {
await user
?.createExternalAccount({
strategy,
Expand Down Expand Up @@ -67,11 +85,11 @@ export default function AddAccount() {
{user?.externalAccounts.map((account) => {
return (
<tr key={account.id}>
<td>{capitalizeProvider(account.provider)}</td>
<td>{capitalize(account.provider)}</td>
<td>{account.approvedScopes}</td>
<td>
{account.verification?.status &&
capitalizeProvider(account.verification?.status)}
capitalize(account.verification?.status)}
</td>
<td>
<button onClick={() => account.destroy()}>Remove</button>
Expand All @@ -89,8 +107,8 @@ export default function AddAccount() {
{unconnectedOptions.map((strategy) => {
return (
<li key={strategy}>
<button onClick={() => addOAuth(strategy)}>
Add {capitalizeProvider(strategy.split('_')[1])}
<button onClick={() => addSSO(strategy)}>
Add {capitalize(strategy.split('_')[1])}
</button>
</li>
)
Expand Down

0 comments on commit c2d6fff

Please sign in to comment.