Quickstart
Select a framework to start:- Next.js - App
- Next.js - Pages
- React
- Vanilla JS
Example app
Next.js code example
Web demo
Try out the login flow
SDK reference
Next.js SDK reference
Before you start
- Have a
public_tokenfrom your Stytch project & environment. - Enable and configure Frontend SDKs in your Dashboard.
- Add your application’s domain to your project’s Authorized Domains.
Install the Next.js SDK and configure your API key
- In your Next.js app, run the command to install the SDK:
npm
- Then add your Stytch
public_tokento your project’s.envfile:
.env
Set up a Stytch context provider
- Create a custom
Stytchwrapper component that initializes the Stytch client.
components/stytch-provider.jsx
- Wrap your application with
<Stytch>to provide context to all child components:
app/layout.jsx
Add <StytchLogin> UI component
- Create a
<StytchLogin>component. - Set authentication methods and relevant options in the config object.
components/LoginOrSignupForm.jsx
Add <LoginOrSignupForm> to your login page(s)
- Add
<LoginOrSignupForm>to your/loginpage.
app/login/page.jsx
- If you’re using separate routes, add
<LoginOrSignupForm>to your/authenticateredirect route as well, e.g.app/authenticate/page.jsxorpages/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