Authentication
In this step, we'll set up authentication.
NextAuth.js
Neorepo uses NextAuth.js to handle authentication. NextAuth.js is an open source authentication library for Next.js. It supports a number of authentication providers, including email, GitHub, Google, and more.
Set up the database
NextAuth.js requires a database to store user information. Neorepo uses Planetscale to store user information. Planetscale is a fully managed database service that's built on top of MySQL. It's designed to be a drop-in replacement for MySQL, so you can use the same tools you're already familiar with.
Add your environment variables
- Open the Vercel project you created in the previous step
- Click the "Environment Variables" tab
- Add the following environment variables:
NEXTAUTH_SECRET=somevalue
NEXTAUTH_URL=http://localhost:3000
NextAuth.js uses the NEXTAUTH_SECRET
environment variable to sign cookies. It uses the NEXTAUTH_URL
environment variable to set the next-auth.url
cookie.
Generate a secret
To generate a NEXTAUTH_SECRET, you can run
openssl rand -base64 32
in your terminal or use this website to generate a value.
NextAuth.js URL
NextAuth.js uses the NEXTAUTH_URL
environment variable to set the next-auth.url
cookie. This cookie is used to redirect users back to your app after they've signed in.
We've already set up NEXTAUTH_URL
for you (see package.json
), but you can also set it manually. To do so, set NEXTAUTH_URL
to the URL of your Vercel project.