Backend Setup Guide
Learn how to set up MongoDB+NextAuth or Supabase for your SuperFast application.
Choose Your Stack
SuperFast supports both MongoDB+NextAuth and Supabase for authentication and database. Choose the stack that best fits your needs.
MongoDB + NextAuth Setup
Follow these steps to set up MongoDB and NextAuth for authentication in your SuperFast application.
1. Create a MongoDB Database
First, you need to create a MongoDB database. You can use MongoDB Atlas, which offers a free tier:
- Sign up for a MongoDB Atlas account
- Create a new project and deploy a cluster (the free tier is sufficient for development)
- Set up database access with a username and password
- In your project on MongoDB Atlas, click Network Access then + Add IP Address. Enter
0.0.0.0/0
in Access List Entry. This allows connections from your computer and your production deployment(s) (Vercel for instance). - Get your connection string from the "Connect" button
- Run a local database for your dev setup so you can work offline and it's faster
2. Set Up Google OAuth
To enable Google authentication, follow these steps:
- Add these essential environment variables to your
.env.local
file:
Important
Make sure to replace the placeholder values with your actual credentials:
.env.local
# Essential NextAuth configurationNEXTAUTH_URL=http://localhost:3000NEXTAUTH_SECRET=your-random-string-with-at-least-15-characters# Google OAuth credentials (add these after setting up Google OAuth)AUTH_GOOGLE_ID=your-client-idAUTH_GOOGLE_SECRET=your-client-secret
- Go to the Google Cloud Console
- Create a new project or select an existing one
- Navigate to APIs & Services then Credentials
- Click Configure Consent Screen and fill in the required information
- Go back to Credentials and click + Create Credentials then OAuth Client ID
- Choose Web Application as the application type
- Add these to Authorized JavaScript origins:
http://localhost:3000
https://your-site.com
- Add these to Authorized redirect URIs:
http://localhost:3000/api/auth/callback/google
https://your-site.com/api/auth/callback/google
- Note: If you're using a subdomain like www, make sure to add that too
- Click [Create] and copy the Client ID and Client Secret
- Add these to your
.env.local
:
Important
Make sure to replace the placeholder values with your actual credentials:
.env.local
# Google OAuth credentialsAUTH_GOOGLE_ID=your-client-idAUTH_GOOGLE_SECRET=your-client-secret
- Go to OAuth Consent Screen and click Publish App then submit for verification
- Click Prepare for verification and fill in any missing information
- Important: Google will email you and you'll need to reply to start the verification process. You'll also need to have your domain verified with Google Search Console.
Verification Status
You can already login with Google on localhost. On production, it will work too but show a warning until you're verified (takes a few days). The MongoDB adapter will automatically save new users in the database when they successfully log in with Google.
MongoDB + NextAuth Setup Complete
Your authentication system is now set up with MongoDB and NextAuth. You can use the
auth()
function to protect routes and access user data.