Userbase is the easiest way to add user accounts and data persistence to your static site.
First, you'll need to create a Userbase account. If you don't already have one, you can create one here.
After creating your account, make a note of your App ID. You'll store it later as an environment variable for your project.
Set up a Next.js and Userbase project by initializing the project template and moving into the project directory:
npm init next-app --example with-userbase userbase-todo-app && cd userbase-todo-app
For your app to function correctly, you will need to provide it with an environment variable.
The scaffolded template provides you with a
.env.local.example file. Rename the file to
.env.local and set the value of the environment variable inside
.env.local to your Userbase App ID from Step 1.
.env.local file will look like this:
You are now able to run and develop your Next.js + Userbase app locally with the following command:
To deploy your Next.js + Userbase app with a Vercel for Git, make sure it has been pushed to a Git repository.
During the import process, you will need to add the following environment variable:
Import the project into Vercel using your Git of choice:
After your project has been imported, all subsequent pushes to branches will generate Preview Deployments, and all changes made to the Production Branch (commonly "main") will result in a Production Deployment.
Once deployed, you will get a URL to see your app live, such as the following: https://next-userbase.vercel.app
Set up a Next.js + Userbase app with a few clicks using the Deploy button, and create a Git repository for it in the process for automatic deployments for your updates.