Setting Up NextReady
This guide will walk you through the process of setting up your NextReady SaaS starter kit after cloning it from GitHub.
On this page
Prerequisites
Before you begin setting up NextReady, ensure you have the following installed on your machine:
- Node.js (v18 or higher) - Download
- npm, yarn, or pnpm - Install Yarn or Install pnpm
- Git - Download
You'll also need accounts with the following services:
Project Setup
Clone the Repository
First, clone the NextReady repository from GitHub to your local machine:
git clone https://github.com/your-username/nextready.git cd nextready
Install Dependencies
Install all the required dependencies using npm, yarn, or pnpm:
# Using npm npm install # Using yarn yarn install # Using pnpm pnpm install
Dependency Conflicts Resolution
If you encounter dependency conflicts between next-auth, @auth/core, and @auth/mongodb-adapter, create a .npmrc
file in the root directory with the following content:
legacy-peer-deps=true
This will help resolve conflicts between these packages during installation and deployment.
Environment Variables
NextReady requires several environment variables to function properly. Create a .env.local
file in the root of your project with the following variables:
# App NEXT_PUBLIC_APP_URL=http://localhost:3000 # MongoDB MONGODB_URI=your_mongodb_connection_string # NextAuth NEXTAUTH_SECRET=your_nextauth_secret NEXTAUTH_URL=http://localhost:3000 # Google Authentication GOOGLE_CLIENT_ID=your_google_client_id GOOGLE_CLIENT_SECRET=your_google_client_secret # Stripe STRIPE_SECRET_KEY=your_stripe_secret_key STRIPE_PUBLISHABLE_KEY=your_stripe_publishable_key STRIPE_WEBHOOK_SECRET=your_stripe_webhook_secret STRIPE_PRICE_ID=your_stripe_price_id # Email (Resend) RESEND_API_KEY=your_resend_api_key
Generating a NextAuth Secret
You can generate a secure random string for your NEXTAUTH_SECRET
using this command:
openssl rand -base64 32
MongoDB Setup
NextReady uses MongoDB directly (without Prisma ORM) for data storage. Follow these steps to set up your MongoDB database:
Create a MongoDB Atlas Cluster
- Sign in to MongoDB Atlas
- Create a new project (if you don't have one already)
- Build a new cluster (the free tier is sufficient for development)
- Under "Database Access," create a new database user with read and write privileges
- Under "Network Access," add your IP address or allow access from anywhere for development
- Once your cluster is created, click "Connect" and select "Connect your application"
- Copy the connection string and replace
<password>
with your database user's password - Add this connection string as the
MONGODB_URI
in your.env.local
file
Database Models
NextReady uses Mongoose for MongoDB object modeling. The models are defined in the src/models
directory and include:
User.ts
- User accounts and authenticationPost.ts
- Blog postsContact.ts
- Contact form submissions
Authentication Setup
NextReady uses NextAuth.js for authentication, which supports both credentials (email/password) and Google OAuth.
Setting Up Google Authentication
To enable Google authentication:
- Go to the Google Cloud Console
- Create a new project or select an existing one
- Navigate to "APIs & Services" > "Credentials"
- Click "Create Credentials" and select "OAuth client ID"
- Configure the consent screen if prompted
- For the application type, select "Web application"
- Add authorized JavaScript origins:
http://localhost:3000
(for development) and your production URL - Add authorized redirect URIs:
http://localhost:3000/api/auth/callback/google
(for development) andhttps://your-production-domain.com/api/auth/callback/google
(for production) - Click "Create" and note your Client ID and Client Secret
- Add these values to your
.env.local
file asGOOGLE_CLIENT_ID
andGOOGLE_CLIENT_SECRET
Email/Password Authentication
Email/password authentication is already configured in the project. Users can register and log in using their email and password. The passwords are securely hashed using bcrypt before being stored in the database.
Stripe Setup
NextReady integrates with Stripe for payment processing. Follow these steps to set up Stripe:
Create a Stripe Account
- Sign up for a Stripe account if you don't have one
- In the Stripe Dashboard, ensure you're in test mode (toggle in the top-right corner)
- In the Stripe Dashboard, go to "Developers" > "API keys"
- Copy your "Secret key" and "Publishable key"
- Add these to your
.env.local
file asSTRIPE_SECRET_KEY
andSTRIPE_PUBLISHABLE_KEY
Create a Stripe Product and Price
- In the Stripe Dashboard, go to "Products" > "Add product"
- Enter product details (name, description, etc.)
- Add pricing information (one-time or recurring)
- Click "Save product"
- Find the Price ID for the product you created (it starts with "price_")
- Add this Price ID to your
.env.local
file asSTRIPE_PRICE_ID
Set Up Stripe Webhooks
Webhooks allow Stripe to notify your application when events occur, such as successful payments:
- In the Stripe Dashboard, go to "Developers" > "Webhooks"
- Click "Add endpoint"
- For local development, you can use a tool like Stripe CLI to forward webhooks to your local server
- For production, enter your webhook URL: <code>https://your-domain.com/api/webhooks/stripe</code>
- Select the events to listen for (at minimum: <code>checkout.session.completed</code>, <code>customer.subscription.created</code>, <code>customer.subscription.updated</code>, <code>customer.subscription.deleted</code>)
- Click "Add endpoint" and copy the signing secret
- Add this to your
.env.local
file asSTRIPE_WEBHOOK_SECRET
Important Note
When working with Stripe webhooks, ensure that the payment status checks are looking for <code>succeeded</code> status (not <code>completed</code>) to avoid payment processing issues.
Email Setup
NextReady uses Resend for sending transactional emails. Follow these steps to set up email functionality:
Create a Resend Account
- Sign up for a Resend account
- Verify your domain or use the provided sandbox domain for testing
- Create an API key in the Resend dashboard
- Add this API key to your
.env.local
file asRESEND_API_KEY
Email templates are located in the src/services/email-service.ts
file. You can customize these templates to match your branding.
Internationalization Setup
NextReady supports multiple languages using next-intl. The supported languages are:
- English (en)
- French (fr)
- Spanish (es)
- German (de)
Language Configuration
The internationalization is already set up in the project. The routing structure uses subpaths (/en, /fr, etc.) to differentiate between language versions of the site.
Translation files are located in the messages
directory at the root of the project. Each language has its own subdirectory with JSON files containing the translations.
Running the Project
Once you've set up all the required environment variables and configurations, you can start the development server:
# Using npm npm run dev # Using yarn yarn dev # Using pnpm pnpm dev
Your NextReady application should now be running at http://localhost:3000.
Creating an Admin User
To access the admin dashboard, you'll need to create an admin user:
- Register a new user through the sign-up page
- Access your MongoDB database (through MongoDB Atlas or another tool)
- Find the user document in the "users" collection
- Add a
role
field with the value"admin"
to the user document
Once the user's role is set to "admin", you'll be able to access the admin dashboard and manage blog posts, contacts, and other features.
Deployment
NextReady can be deployed to various platforms. Here's how to deploy to Vercel, which is recommended for Next.js applications:
Deploying to Vercel
- Push your project to a Git repository (GitHub, GitLab, or Bitbucket)
- Sign up for a Vercel account
- Click "New Project" and import your repository
- Configure your project settings (you can leave most as default)
- Add all your environment variables from
.env.local
to the Vercel project settings - Update
NEXTAUTH_URL
andNEXT_PUBLIC_APP_URL
to your production URL - Click "Deploy"
Deployment Troubleshooting
If you encounter dependency conflicts during deployment on Vercel, add a .npmrc
file with legacy-peer-deps=true
to your project root. This helps resolve conflicts between next-auth, @auth/core, and @auth/mongodb-adapter.
After Deployment
After deploying your application:
- Update your Google OAuth redirect URIs to include your production URL
- Update your Stripe webhook endpoint to your production webhook URL
- Test the authentication, payment, and internationalization features in the production environment
Need Help?
If you encounter any issues during setup or have questions, check out our other documentation pages or reach out for support.