From 0a5b33538f5a26547ece2c2e008a299fb06d9dbf Mon Sep 17 00:00:00 2001 From: Alexis Aguilar <98043211+alexisintech@users.noreply.github.com> Date: Thu, 30 Jan 2025 16:35:07 -0500 Subject: [PATCH] docs review --- .../expo/deprecated-oauth-custom-flow.mdx | 58 ------------------ .../expo/enterprise-sso-custom-flow.mdx | 28 ++++++--- docs/_partials/expo/oauth-custom-flow.mdx | 11 ++-- docs/custom-flows/enterprise-connections.mdx | 36 ++++++----- docs/custom-flows/oauth-connections.mdx | 40 +++++------- docs/references/expo/overview.mdx | 17 +++--- docs/references/expo/use-oauth.mdx | 61 ++++++++++++++++++- docs/references/expo/use-sso.mdx | 55 ++++++++++++++++- docs/references/expo/web-support/overview.mdx | 9 +-- 9 files changed, 186 insertions(+), 129 deletions(-) delete mode 100644 docs/_partials/expo/deprecated-oauth-custom-flow.mdx diff --git a/docs/_partials/expo/deprecated-oauth-custom-flow.mdx b/docs/_partials/expo/deprecated-oauth-custom-flow.mdx deleted file mode 100644 index 81f09bee6c..0000000000 --- a/docs/_partials/expo/deprecated-oauth-custom-flow.mdx +++ /dev/null @@ -1,58 +0,0 @@ -The following example demonstrates how to create a custom OAuth sign-in flow for [Google accounts](/docs/authentication/social-connections/google). - -```tsx {{ filename: 'app/(auth)/sign-in.tsx', collapsible: true }} -import React from 'react' -import * as WebBrowser from 'expo-web-browser' -import { Text, View, Button } from 'react-native' -import { Link } from 'expo-router' -import { useOAuth } from '@clerk/clerk-expo' -import * as Linking from 'expo-linking' - -export const useWarmUpBrowser = () => { - React.useEffect(() => { - // Warm up the android browser to improve UX - // https://docs.expo.dev/guides/authentication/#improving-user-experience - void WebBrowser.warmUpAsync() - return () => { - void WebBrowser.coolDownAsync() - } - }, []) -} - -WebBrowser.maybeCompleteAuthSession() - -export default function Page() { - useWarmUpBrowser() - - const { startOAuthFlow } = useOAuth({ strategy: 'oauth_google' }) - - const onPress = React.useCallback(async () => { - try { - const { createdSessionId, signIn, signUp, setActive } = await startOAuthFlow({ - redirectUrl: Linking.createURL('/dashboard', { scheme: 'myapp' }), - }) - - // If sign in was successful, set the active session - if (createdSessionId) { - setActive!({ session: createdSessionId }) - } else { - // Use signIn or signUp returned from startOAuthFlow - // for next steps, such as MFA - } - } catch (err) { - // See https://clerk.com/docs/custom-flows/error-handling - // for more info on error handling - console.error(JSON.stringify(err, null, 2)) - } - }, []) - - return ( - - - Home - - ) } ``` - ```jsx {{ filename: 'app/sign-up/sso-callback/page.tsx' }} + ```jsx {{ filename: 'app/sign-in/sso-callback/page.tsx' }} import { AuthenticateWithRedirectCallback } from '@clerk/nextjs' export default function Page() { @@ -78,10 +80,16 @@ The following example shows two files: ``` + + + + ## Enterprise account transfer flows +{/* TODO(Laura): I believe this is built in with Expo's `useSSO()` hook, so I don't think we need to add Expo example here. Is this correct? */} + It is common for users who are authenticating with an enterprise account to use a sign-in button when they mean to sign-up, and vice versa. For those cases, the `SignIn` and `SignUp` objects have a `transferable` status that indicates whether the user can be transferred to the other flow. **If you would like to keep your sign-in and sign-up flows completely separate, then you can skip this section.** @@ -90,7 +98,7 @@ The following example demonstrates how to handle these cases in your sign-in flo - ```tsx {{ filename: 'app/sign-in/[[...sign-in]]/page.tsx', collapsible: true }} + ```tsx {{ filename: 'app/sign-in/page.tsx', collapsible: true }} 'use client' import * as React from 'react' @@ -111,7 +119,7 @@ The following example demonstrates how to handle these cases in your sign-in flo .authenticateWithRedirect({ identifier: email, strategy: 'enterprise_sso', - redirectUrl: '/sign-up/sso-callback', + redirectUrl: '/sign-in/sso-callback', redirectUrlComplete: '/', }) .then((res) => { diff --git a/docs/custom-flows/oauth-connections.mdx b/docs/custom-flows/oauth-connections.mdx index 3456fe07f6..880d9a6462 100644 --- a/docs/custom-flows/oauth-connections.mdx +++ b/docs/custom-flows/oauth-connections.mdx @@ -39,11 +39,21 @@ When using OAuth, the sign-up and sign-in flows are equivalent. if (!signIn) return null const signInWith = (strategy: OAuthStrategy) => { - return signIn.authenticateWithRedirect({ - strategy, - redirectUrl: '/sign-up/sso-callback', - redirectUrlComplete: '/', - }) + return signIn + .authenticateWithRedirect({ + strategy, + redirectUrl: '/sign-up/sso-callback', + redirectUrlComplete: '/', + }) + .then((res) => { + console.log(res) + }) + .catch((err: any) => { + // See https://clerk.com/docs/custom-flows/error-handling + // for more info on error handling + console.log(err.errors) + console.error(err, null, 2) + }) } // Render a button for each supported OAuth provider @@ -70,26 +80,6 @@ When using OAuth, the sign-up and sign-in flows are equivalent. - ### Before you start - - Install `expo-linking` to handle linking. - - - ```bash {{ filename: 'terminal' }} - npm install expo-linking - ``` - - ```bash {{ filename: 'terminal' }} - yarn add expo-linking - ``` - - ```bash {{ filename: 'terminal' }} - pnpm add expo-linking - ``` - - - ### Build the flow - diff --git a/docs/references/expo/overview.mdx b/docs/references/expo/overview.mdx index cdf3aa3bc5..36a05e22c0 100644 --- a/docs/references/expo/overview.mdx +++ b/docs/references/expo/overview.mdx @@ -11,20 +11,23 @@ The Expo SDK gives you access to the following resources: ### Clerk hooks {{ id: 'hooks' }} -The following hooks are available for both **native** and **web** apps: +The Expo SDK provides the following hooks: -- All React hooks are available. See [the React docs](/docs/references/react/overview){{ target: '_blank' }} for more information. - [`useSSO()`](/docs/references/expo/use-sso) - [`useLocalCredentials()`](/docs/references/expo/use-local-credentials) +Because the Expo SDK is built on top of the Clerk React SDK, you can use the hooks that the React SDK provides. These hooks include access to the [`Clerk`](/docs/references/javascript/clerk/clerk) object, [`User` object](/docs/references/javascript/user/user), [`Organization` object](/docs/references/javascript/organization/organization), and a set of useful helper methods for signing in and signing up. + + + ### Clerk components {{ id: 'components' }} - **Native** apps: - - [``](/docs/components/control/clerk-loaded){{ target: '_blank' }} - - [``](/docs/components/control/clerk-loading){{ target: '_blank' }} - - [``](/docs/components/control/signed-in){{ target: '_blank' }} - - [``](/docs/components/control/signed-out){{ target: '_blank' }} - - [``](/docs/components/protect){{ target: '_blank' }} + - [``](/docs/components/control/clerk-loaded) + - [``](/docs/components/control/clerk-loading) + - [``](/docs/components/control/signed-in) + - [``](/docs/components/control/signed-out) + - [``](/docs/components/protect) - **Web** apps: - All Clerk components are available. See [the component docs](/docs/components/overview) for more information. diff --git a/docs/references/expo/use-oauth.mdx b/docs/references/expo/use-oauth.mdx index 9fb23a157e..b0f3650d0b 100644 --- a/docs/references/expo/use-oauth.mdx +++ b/docs/references/expo/use-oauth.mdx @@ -1,5 +1,5 @@ --- -title: useOAuth() +title: useOAuth() (deprecated) description: Clerk's useOAuth() hook is used to create a new OAuth flow. --- @@ -61,4 +61,61 @@ It accepts the following parameters (`StartOAuthFlowParams`): ## How to use the `useOAuth()` hook - +The following example demonstrates how to create a custom OAuth sign-in flow for [Google accounts](/docs/authentication/social-connections/google). + +```tsx {{ filename: 'app/(auth)/sign-in.tsx', collapsible: true }} +import React from 'react' +import * as WebBrowser from 'expo-web-browser' +import { Text, View, Button } from 'react-native' +import { Link } from 'expo-router' +import { useOAuth } from '@clerk/clerk-expo' +import * as Linking from 'expo-linking' + +export const useWarmUpBrowser = () => { + React.useEffect(() => { + // Warm up the android browser to improve UX + // https://docs.expo.dev/guides/authentication/#improving-user-experience + void WebBrowser.warmUpAsync() + return () => { + void WebBrowser.coolDownAsync() + } + }, []) +} + +WebBrowser.maybeCompleteAuthSession() + +export default function Page() { + useWarmUpBrowser() + + const { startOAuthFlow } = useOAuth({ strategy: 'oauth_google' }) + + const onPress = React.useCallback(async () => { + try { + const { createdSessionId, signIn, signUp, setActive } = await startOAuthFlow({ + redirectUrl: Linking.createURL('/dashboard', { scheme: 'myapp' }), + }) + + // If sign in was successful, set the active session + if (createdSessionId) { + setActive!({ session: createdSessionId }) + } else { + // Use signIn or signUp returned from startOAuthFlow + // for next steps, such as MFA + } + } catch (err) { + // See https://clerk.com/docs/custom-flows/error-handling + // for more info on error handling + console.error(JSON.stringify(err, null, 2)) + } + }, []) + + return ( + + + Home + +