This project is a boilerplate for user authentication and registration using Next.js, MongoDB, and TypeScript. It includes features such as email verification, multi-factor authentication (MFA), and password hashing.
Clone the repository:
git clone https://github.com/your-username/next-login-boilerplate.git
cd next-login-boilerplate
Install dependencies:
npm install
Create a .env
file in the root directory and add the following environment variables:
DOMAIN=http://localhost:3000
[email protected]
MAIL_HOST=smtp.example.com
MAIL_PORT=465
[email protected]
MAIL_PASS=your-email-password
MONGO_URL=mongodb://localhost:27017/your-database
TOKEN_SECRET=your-secret-key-here
Make sure to use a strong, random string for your TOKEN_SECRET in production. You can generate one using a secure random generator or use a command like this in your terminal:
node -e "console.log(require('crypto').randomBytes(64).toString('hex'))"
Start the development server:
npm run dev
src/
: Contains the source code for the project.app/
: Contains the Next.js pages and API routes.api/
: contains APIs for the projectcommon/
: Contains common utilities, types, and constants.services/
: Contains service classes for authentication, mailing, etc.models/
: Contains Mongoose models for MongoDB collections.