Run the following command to install all required dependencies:
npm install --legacy-peer-deps
Create a .env
file in the project root and add the following environment variables:
AUTH_SECRET=
DATABASE_URL=
UPLOADTHING_TOKEN=
NEXTAUTH_URL="http://localhost:3000"
AUTH_TRUST_HOST=true
-
AUTH_SECRET
– A secret key used for authentication. You can generate a secure string using OpenSSL it the git terminal:openssl rand -hex 32
-
DATABASE_URL
– Your PostgreSQL database connection string. Use the following format:postgresql://<username>:<password>@<host>:<port>/postgres
Replace
<username>
,<password>
,<host>
, and<port>
with your actual database credentials. -
UPLOADTHING_TOKEN
– An API token for UploadThing. To obtain this:- Create an account on UploadThing.
- Set up a project.
- Copy your token and paste it into the
.env
file.
After configuring the .env file, generate the Prisma client and apply migrations to set up the database schema:
npx prisma migrate dev
This ensures Prisma is properly set up before you start the server.
After setting up your environment, you can start the development server:
npm run dev
Now we'll create our first admin user. Navigate to http://localhost:3000/admin/create-first-user
- NOTE: After creating the first admin user, this page will not be accessible anymore, unless you clear the database. Please be careful and do not forget your admin credentials.
To start a production build, run the following command:
npm run build
npm run start
NOTE: Please make sure to configure your environment variables because, auth.js may fail.