website logo
Navigate through spaces
Chord Commerce
⌘K
Getting Started
CMS
Data
OMS
Integrations
👩‍💻Developer Tools
Shopify
Docs powered by archbee 

Next.js ↔️ Stytch Migration Guide

Stytch Account Setup

Create your Stytch account following our Stytch Account Setup guide.

Add your public key to the .env

You can find your public token in the Stytch dashboard.

Text
|

Also remove the magic key from your .env if you have one.

Install Stytch and chord-stytch

Shell
|

Add a StytchProvider

Visit the file where you wrap your app in ChordProvider and add a stytchClient:

JS
|

Then, pass the stytchClient to the auth prop of the ChordProvider:

JS
|

Finally, wrap children with a StytchProvider (import from @stytch/nextjs) and pass stytchClient.getServiceClient() to it:

JS
|

Add a LoginForm component that uses StytchLogin

Go to the config docs to see what options are available. Please note that you will need to wrap the <StytchLogin /> component with another <StytchProvider /> . This is because the <StytchLogin /> component depends on Stytch's UI client, which is quite heavy, and that chord-stytch uses the headless client for it's normal operations.

StytchLoginForm

Create an Authenticate component

This component will authenticate the user by calling handleCallback() from useAuth, then it will navigate to the /account page.

Add this component to the pages directory.

Authenticate

Try it out

Visit your login page and try logging in using a magic link!

Once you've clicked the link in the email from Stytch to sign-up/login, you can visit the User management page to see your user.

Enabling OAuth

If your would like to enable OAuth, visit the SDK Configuration page, and click the OAuth toggle. Then, expand the OAuth section and toggle Enable PKCE.

Once OAuth is enabled, visit the OAuth page, then select the provider you would like to use and follow the directions.

Updated 11 Jan 2023
Did this page help you?
Yes
No
UP NEXT
Gatsby ↔️ Stytch Migration Guide
Docs powered by archbee 
StytchLoginForm