Skip to main content

Quickstart

Select a framework to start:

Example app

Next.js code example

Web demo

Try out the login flow

SDK reference

Next.js SDK reference
1

Before you start

  • Have a public_token from your Stytch project & environment.
  • Enable and configure Frontend SDKs in your Dashboard.
  • Add your application’s domain to your project’s Authorized Domains.
2

Install the Next.js SDK and configure your API key

  1. In your Next.js app, run the command to install the SDK:
npm
  1. Then add your Stytch public_token to your project’s .env file:
.env
3

Set up a Stytch context provider

  1. Create a custom Stytch wrapper component that initializes the Stytch client.
components/stytch-provider.jsx
  1. Wrap your application with <Stytch> to provide context to all child components:
app/layout.jsx
4

Add <StytchLogin> UI component

  1. Create a <StytchLogin> component.
  2. Set authentication methods and relevant options in the config object.
components/LoginOrSignupForm.jsx
5

Add <LoginOrSignupForm> to your login page(s)

  1. Add <LoginOrSignupForm> to your /login page.
app/login/page.jsx
  1. If you’re using separate routes, add <LoginOrSignupForm> to your /authenticate redirect route as well, e.g. app/authenticate/page.jsx or pages/authenticate.jsx.

Handle session and user data

At this point, you can retrieve Session data and User data via the SDK. For example, useStytchSession() lets you easily check for an active session.

Next steps

  • Authentication methods
  • Session management