For Authenticating using Username and Password, we are using SQL Database with the Prisma ORM.
We are going to use the PlanetScale database to show you, how to integrate the database with the Next.js template.
Feel free to choose any SQL database that fits your requirements.
Login to your PlanetScale account and follow the steps to create a Database and generate a URL.
Add the Name and choose the Region from the dropdown menu and then click on the Create Database.
DATABASE_URL=YOUR_DB_CONNECT_URL
Now that you’ve added the connection string to the .env file you have to push the schema to the PlanetScale Database you created earlier.
Run this command to push the schema to PlanetScale.
npx prisma db push
If the code runs properly the schema will be added to the PlanetScale Database. You can go to the Console and run show tables; to see the Schema.
Now run this command.
npx prisma generate
Go ahead and signup using the form. If everything is done properly you’ll see the user on your PlanetScale database.
In the Solid starter template, we used Vercel Postgres Database for Authentication. In this part of the documentation, we are going to show you you can integrate Vercel Postgres with the Next.js template.
Before we integrate the database in the template first you have to deploy it to Vercel.
Once you deploy it follow the instruction to create the database.
After that select Postgres and then the Continue button. ****
Now do the following to create a new database:
The Database is created successfully.
Because we created the database in a project, we won’t have to add the environment variables manually to Vercel. It’ll be added automatically.
Now we have to pull the environment variables to the local project.
To do that, first of all, you have to install Vercel CLI
npm i -g vercel@latest
After that run this command to pull the .env variables.
vercel env pull .env
Note: You have to connect the local project with Vercel for this command to work. Follow this instruction to link the project.
Now that you’ve added the connection string to the .env file you have to push the schema to the Database you created earlier.
Run this command to push the schema to Vercel Storage.
npx prisma db push
After you run this you’ll be able to see the Tables on Vercel Storage.
Now run this command
npx prisma generate
Now go ahead and signup using the Form. If everything was done properly you’ll see the user on the Database.
Make sure you run Prisma generate command before the final build
prisma generate
then
npm run build
Also, while deploying your app on Vercel, edit build command and make it like the screenshot below: