A robust and secure user authentication system built using Next.js. This project includes user signup, login, email verification, and password reset functionalities, demonstrating the integration of modern web technologies.
- User Signup: Securely register users with email and password.
- Login: Authenticate users with encrypted passwords.
- Email Verification: Verify users' email addresses via unique token-based links.
- Password Reset: Allow users to reset forgotten passwords.
- Environment Variables: Keep sensitive credentials secure using
.env.
- Frontend: Next.js, TailwindCSS
- Backend: Node.js, MongoDB, Mongoose, Axios
- Email Service: Nodemailer (with Mailtrap)
- State Management: React hooks
- Security: Bcrypt.js for password hashing, JWT for token management
-
Clone the repository:
git clone https://github.com/Farru049/Authentication-Next.js.git cd Authentication-Next.js -
Install dependencies:
npm install
-
Setup environment variables: Create a
.envfile and configure the following:MONGODB_URI=<Your_MongoDB_URI> TOKEN_SECRET=<Your_Secret_Token> DOMAIN=<Your_Domain_or_Localhost> MAILTRAP_USER=<Your_Mailtrap_User> MAILTRAP_PASS=<Your_Mailtrap_Password> -
Run the development server:
npm run dev
Access the application at
http://localhost:3000.
-
Signup:
- Users provide their email, password, and username.
- A verification email is sent with a unique token.
-
Email Verification:
- Users click the link sent to their email to verify their account.
- The token is validated against the database.
-
Login:
- Users log in with their email and password.
- Credentials are verified against hashed passwords stored in MongoDB.
-
Password Reset:
- Users can request a password reset link.
- A reset token is emailed, allowing them to update their password.
.
├── src/
│ ├── app/
│ │ ├── login/
│ │ ├── signup/
│ │ ├── verifyemail/
│ │ └── api/
│ │ ├── users/
│ │ │ ├── signup/
│ │ │ ├── login/
│ │ │ └── verifyemail/
│ ├── models/
│ ├── dbConfig/
│ └── utils/
├── public/
└── .env.example
For a live demo or screenshots, visit the repository: Authentication-Next.js.
Contributions are welcome! Please open an issue or submit a pull request with your changes.
This project is licensed under the MIT License. See the LICENSE file for details.