AuthX is a simple and flexible system for handling user logins and signups. It comes with the basic features you need, like creating accounts, logging in, verifying emails, resetting passwords, and giving users access to certain areas using JWT.
It’s a great starting point if you need to set up full authentication for your app. The frontend is made with React, the backend runs on Express, and MongoDB is used as the database. You can easily change or add features to fit your project.
Frontend:
- React for the user interface and state management.
Backend:
- Express for handling server-side logic and API routes.
- MongoDB for database storage and Mongoose for data modeling.
- Mailtrap for email services (email verification, password reset).
Security:
- JWT for authentication and secure token management.
- Bcrypt for password hashing.
Other Tools:
- Dotenv for managing environment variables.
- Cookie-parser for handling cookies in requests.
- User Registration: Users can sign up with email and password.
- User Login: Secure login functionality with hashed passwords and JWT.
- Email Verification: Users receive a verification email to verify their account.
- Password Reset: Allows users to reset their password via email link.
- Token-based Authentication: Protects routes with JWT token verification.
- User Logout: Handles secure token invalidation.
- Authentication Middleware: Ensures protected routes are only accessible to authenticated users.
- Node.js installed on your system.
- MongoDB instance (local or cloud, such as MongoDB Atlas).
- Mailtrap account for email services.
-
Clone the repository:
git clone https://github.com/ramxcodes/AuthX.git
-
Navigate into the project directory:
cd AuthX
-
Install server dependencies:
npm install
-
Install front end dependencies:
cd frontend npm install cd ..
-
Create a
.env
file in the root directory and add the following environment variables:MONGO_URI = MONGO_URL PORT = 5000/3000 JWT_SECRET= YOUR_SECRET NODE_ENV= DEVELOPMENT/PRODUCTION MAILTRAP_TOKEN= YOUR_MAILTRAP_TOKEN CLIENT_URL= YOUR_LOCAL/ONLINE_URL (http://localhost:5173)
-
Start the backend server:
npm start
-
Start the React frontend:
cd client npm start
-
Visit your app at
http://localhost:5173
(for frontend) and the API is accessible athttp://localhost:5000/api
.
- POST /api/auth/signup: Register a new user.
- POST /api/auth/login: Login an existing user.
- POST /api/auth/logout: Logout the current user.
- POST /api/auth/verify-email: Verify user's email using a token.
- POST /api/auth/forgot-password: Request a password reset email.
- POST /api/auth/reset-password/:token: Reset password using the reset token.
- GET /api/auth/check-auth: Check user authentication status (requires token).
This project is licensed under the MIT License.
- Name: Ramkrishna Swarnkar
- GitHub: @ramxcodes
- LinkedIn: @ramxcodes
- Twitter: @ramxcodes