Build a custom flow for authenticating with OAuth connections
Before you start
You must configure your application instance through the Clerk Dashboard for the social connection(s) that you want to use, as described at the top of the OAuth guide.
Create the sign-up and sign-in flow
When using OAuth, the sign-up and sign-in flows are equivalent.
A successful OAuth flow consists of the following steps:
- Start the OAuth flow by calling
SignIn.authenticateWithRedirect(params)
orSignUp.authenticateWithRedirect(params)
. Both of these methods require aredirectUrl
param, which is the URL that the browser will be redirected to once the user authenticates with the OAuth provider. - Create a route at the URL that the
redirectUrl
param points to. The following example names this route/sso-callback
. This route should call theClerk.handleRedirectCallback()
method or simply render the prebuilt<AuthenticateWithRedirectCallback/>
component.
The following example shows two files:
- The sign-in page where the user can start the OAuth flow.
- The SSO callback page where the OAuth flow is completed.
Before you start
Install expo-linking
to handle linking.
Build the flow
The following example demonstrates a component that creates a custom OAuth sign-in flow for Google accounts.
OAuth account transfer flows
It is common for users who are authenticating with OAuth 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.
The following example demonstrates how to handle these cases in your sign-in flow. To apply the same logic to the sign-up flow, simply replace signIn.authenticateWithRedirect()
with signUp.authenticateWithRedirect()
in your code.
Feedback
Last updated on