This guide will help you set up the necessary environment variables for this Next.js project. Follow these steps to obtain and configure each required variable.
- Sign up for a MongoDB Atlas account at https://www.mongodb.com/cloud/atlas if you haven't already.
- Create a new cluster or use an existing one.
- In the Atlas dashboard, click on "Connect" for your cluster.
- Choose "Connect your application".
- Select "Node.js" as your driver and choose the appropriate version.
- Copy the connection string provided. It will look something like this:
mongodb+srv://<username>:<password>@<cluster-name>.mongodb.net/<database-name>?retryWrites=true&w=majority
- Replace
<username>
and<password>
with your MongoDB Atlas database user credentials. - Replace
<database-name>
with the name of your database. - Set
DATABASE_URL
in your.env
file to this complete connection string.
- Go to UploadThing and create an account.
- Create a new project in the UploadThing dashboard.
- In your project settings, find the
UPLOADTHING_SECRET
andUPLOADTHING_APP_ID
. - Copy these values to your
.env
file.
- Generate a secure random string for
NEXTAUTH_SECRET
. You can use a tool like generate-secret.vercel.app. - Set
NEXTAUTH_URL
to your application's base URL (e.g.,http://localhost:3000
for local development or your deployed URL for production).
- Go to GitHub Developer Settings.
- Click "New OAuth App".
- Fill in the application details:
- Application name: Your app's name
- Homepage URL: Your app's URL
- Authorization callback URL:
{NEXTAUTH_URL}/api/auth/callback/github
- After creating the app, you'll see the
Client ID
andClient Secret
. - Set
GITHUB_CLIENT_ID
andGITHUB_SECRET
with these values.
- Go to the Google Cloud Console.
- Create a new project or select an existing one.
- Go to "APIs & Services" > "Credentials".
- Click "Create Credentials" > "OAuth client ID".
- Set the application type to "Web application".
- Add authorized redirect URIs:
{NEXTAUTH_URL}/api/auth/callback/google
- After creating, you'll get the
Client ID
andClient Secret
. - Set
GOOGLE_CLIENT_ID
andGOOGLE_CLIENT_SECRET
with these values.
Remember to never commit your .env
file to version control. Add it to your .gitignore
file to prevent accidental exposure of sensitive information.