Add Fauna User Authentication to a Next.js App

Share this video with your friends

Send Tweet

To have actual users in our application we need to represent those users in our database. Fauna has quite a few ways you can do user authentication but we'll be creating our own using a few built-in Fauna helpers.

We'll start by setting up the necessary Fauna logic for users. We'll add a User collection as well as a functions.fsl file that we'll expose user sign up and log in. Here we'll see how Fauna gives us a built in Credentials document to handle email and password for a user. It also has a login function that it exposes to make that easy for us which will generate a token for a user on login.

After setting up our functions, we'll add an UnAuthRole as well as an AuthRole and give proper actions for each role.