Skip to main content
Our frontend SDK provide automatic session management, prebuilt login or signup, multi-step flow handling, and more. They can also be used alongside our backend API or SDKs.

Quickstart

This quickstart guides you through building a Discovery login flow. Select a framework:

Example apps

Node.js code examples

Web demo

Hosted Node.js demo

Node.js SDK

Stytch Node.js library

API reference

API & SDK references
1

Before you start

  • Have your public_token and secret_key from your Stytch project & environment.
  • While the guide uses Express, the Node.js SDK is framework agnostic.
2

Install the Node.js SDK and configure API keys

  1. Install the SDK in your Express environment:
npm
  1. Then add your Stytch API keys to your project’s .env file:
.env
3

Set up your app and login routes

  1. Initialize the Stytch client with your environment variables.
  2. Create a /login route that takes in a user’s email address and initiates the login or signup flow.
POST '/login'
4

Add a route to handle Stytch's redirect callback

  1. Stytch calls the authenticate redirect URL with a token to complete a user’s authentication flow.
  2. Add an /authenticate route to handle the redirect callback in your app.
GET '/authenticate'
5

Log in to an organization

  1. At this point, a user has been authenticated but still needs to specify an Organization to log in to and begin a session.
  2. Stytch provides an intermediate_session_token that you can use to preserve the user’s authentication state while you provide them with options to proceed (e.g. selecting from a list of organizations).
  3. For this example, we’ll add logic to automatically sign in to an existing organization or create one if none already exist:
GET '/authenticate'
6

Add a session-protected route

  1. Create a helper method that returns the user’s Session information.
  2. Use the method to gate any protected route that should only be accessed by an authenticated user.
GET '/dashboard'
7

Full completed example:

Test your application

  • Run your application and send a POST request to the /login endpoint with your email address.
  • You should receive an email magic link in your inbox.
  • Click on the magic link you recieved to finish the login or signup flow.

Next steps

  • Handle a session