Prerequisites
Before this: create and initialize a Dynamic client (see Creating a Dynamic Client, Initializing the Dynamic Client). Enable at least one social provider (Google, Discord, GitHub, etc.) in your Dynamic dashboard.How social login works
Social login uses OAuth, a protocol that delegates authentication to a third-party provider. The flow has three steps:- Redirect out — your app sends the user to the provider’s login page (e.g. Google’s sign-in screen).
- Provider authenticates — the user signs in with the provider. The provider redirects back to your app with an authorization code in the URL.
- Complete authentication — your app detects the redirect, extracts the code, and exchanges it for a Dynamic session.
detectSocialRedirectUrl— checks whether the current page load is an OAuth callback.completeSocialRedirect— finishes the authentication and creates the user session.
Implementation
- TypeScript
- React
The redirect detection must run on every page load — before you render your main application. If the current URL contains OAuth parameters, complete the authentication before proceeding.Key points:
redirectUrldoes not need to be a dedicated callback route. It can be your app’s root URL — the SDK uses URL parameters, not a specific path, to identify the callback.detectSocialRedirectUrlis cheap — it only checks for two URL parameters (dynamicOauthStateanddynamicOauthCode). Call it on every load without performance concerns.completeSocialRedirectreturns the authenticatedUserobject, ornullif authentication failed.
Handling errors
BothdetectSocialRedirectUrl and completeSocialRedirect can throw:
Popup-based social login is not supported on web
On web, the redirect flow is the only supported approach for social login —signInWithSocialPopUp throws a MethodNotImplementedError if called in a browser.
Multiple providers
Dynamic supports Google, Apple, Discord, GitHub, Facebook, Microsoft, LinkedIn, X (Twitter), Twitch, TikTok, Steam, Epic Games, and Kraken. Enable the ones you want in the dashboard, then render a button for each:detectSocialRedirectUrl + completeSocialRedirect call handles any provider.
See also
- Email & SMS OTP sign-in — add code-based login alongside social
- Authenticate with social — social auth reference
- Social linking — link additional social accounts to an existing user
- Authentication concepts — users, sessions, and credentials