Skip to main content

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:
  1. Redirect out — your app sends the user to the provider’s login page (e.g. Google’s sign-in screen).
  2. Provider authenticates — the user signs in with the provider. The provider redirects back to your app with an authorization code in the URL.
  3. Complete authentication — your app detects the redirect, extracts the code, and exchanges it for a Dynamic session.
Step 3 happens automatically in a traditional server-rendered app, but in a single-page app you need to handle it yourself. The SDK gives you two functions for this:
  • detectSocialRedirectUrl — checks whether the current page load is an OAuth callback.
  • completeSocialRedirect — finishes the authentication and creates the user session.
If you skip the redirect detection step, users who sign in with a social provider will land back on your app without being authenticated. This is the most common cause of “social login doesn’t work” bugs.

Implementation

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:
  • redirectUrl does 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.
  • detectSocialRedirectUrl is cheap — it only checks for two URL parameters (dynamicOauthState and dynamicOauthCode). Call it on every load without performance concerns.
  • completeSocialRedirect returns the authenticated User object, or null if authentication failed.

Handling errors

Both detectSocialRedirectUrl and completeSocialRedirect can throw:
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:
The redirect detection is provider-agnostic — the same detectSocialRedirectUrl + completeSocialRedirect call handles any provider.

See also

Last modified on July 9, 2026