Skip to main content
Use Stytch and PlanetScale to build out your entire user authentication flow and database. Stytch and Planetscale
1

Create your PlanetScale user database

Create your user database with PlanetScale’s pscale command line utility, then create your first database branch.
2

Create your users table

This query creates your users table where you’ll store a record for each user.
3

Create a deploy request, deploy, and merge

4

Create your backend

Establish a connection to PlanetScale, then create the functions to add, remove, and get users from the DB.
5

Instantiate the Stytch client

Instantiate the Stytch client via our stytch-node Backend SDK; you’ll use this SDK to make any calls to the Stytch API. After the user has been authenticated, you will redirect them to the logged-in page where they can take authenticated action.
6

Set up Stytch Email Magic Links

We would like to be able to invite and add new users to our dashboard, we’ll leverage our stytch-node Backend SDK to send Email Magic Links to users to do that.
7

Authenticate Email Magic Links

Next you’ll want a way to authenticate the magic links that are being sent by the Stytch SDK.
8

Set up session management

Now that we’ve got authentication in place, what happens when a user leaves and then comes back? We want that returning user to come back to an authenticated experience, so we will use Stytch’s Session Management API to make that happen.
9

Handle clearing sessions

Now we’ll want to add logic to clear the client state once a session has expired. Doing so will allow us to gracefully re-prompt the user to log in when their session expires; when we initiated the session, we chose a session_duration_minutes of 10080 minutes, 7 days, so that users won’t be prompted to re-login if they return within that 7 day period.
10

You're done

You just finished all the critical backend components in our example. Your app can now login with Stytch Email Magic Links, manage sessions via Sessions Management, and maintain your user database via PlanetScale. You can find an example of this implementation in our Stytch + PlanetScale example app.We can’t wait to see what you build with Stytch! Get in touch with us and tell us what you think at support@stytch.com or in our community Slack.