Skip to main content

Overview

This guide walks through integrating email magic links using Stytch’s headless frontend SDKs. This approach gives you complete control over your UI while handling authentication logic on the frontend.Both and Organization-specific authentication flows are supported.
The Discovery flow is designed for situations where end users are signing up or logging in from a central landing page, and have not specified which they are trying to access.

Prerequisites

  1. Enable the Frontend SDKs in your Stytch Dashboard
  2. Enable Create Organizations under “Enabled Methods”

Implementation

1

Initiate magic link email

In your application’s UI, introduce a way for end users to input their email and trigger a magicLinks.email.discovery.send() method call with the provided email.
2

Handle callback

Stytch will redirect the user to the Discovery RedirectURL you specified on the Redirect URLs page earlier. Exchange the token for a list of Discovered Organizations that the user can choose to log into.
An will be returned. The headless SDK will automatically set this in cookies and include it in follow-up calls.
3

Handle organization selection

When the end user selects an Organization to log into, call the exchange intermediate session method with the selected Organization ID.
4

(Optional) Support organization creation

Allow users to create a new Organization instead of logging into an existing one.
You can optionally prompt the user for the name and slug of their new Organization. If not provided, Stytch will auto-generate them based on the end user’s email address.