{"id":23444806,"url":"https://github.com/akashkobal/mern-authentication","last_synced_at":"2026-02-07T03:01:39.863Z","repository":{"id":268606320,"uuid":"904909100","full_name":"AkashKobal/mern-authentication","owner":"AkashKobal","description":null,"archived":false,"fork":false,"pushed_at":"2024-12-29T13:16:43.000Z","size":440,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T23:42:56.745Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AkashKobal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-17T19:31:44.000Z","updated_at":"2025-02-20T17:39:15.000Z","dependencies_parsed_at":"2025-04-09T23:38:53.616Z","dependency_job_id":null,"html_url":"https://github.com/AkashKobal/mern-authentication","commit_stats":null,"previous_names":["akashkobal/mern-authentication"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AkashKobal/mern-authentication","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AkashKobal%2Fmern-authentication","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AkashKobal%2Fmern-authentication/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AkashKobal%2Fmern-authentication/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AkashKobal%2Fmern-authentication/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AkashKobal","download_url":"https://codeload.github.com/AkashKobal/mern-authentication/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AkashKobal%2Fmern-authentication/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29185111,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-07T00:44:15.062Z","status":"online","status_checked_at":"2026-02-07T02:00:07.217Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-23T19:17:34.734Z","updated_at":"2026-02-07T03:01:39.850Z","avatar_url":"https://github.com/AkashKobal.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MERN Authentication System\n\nA secure and scalable authentication system built using the MERN stack (MongoDB, Express.js, React.js, Node.js). This project supports user registration, login, logout, OTP-based email verification, and JWT-based authentication.\n\n## Features\n\n- **User Registration**: Securely register new users with hashed passwords.\n- **User Login**: Authenticate users with email and password.\n- **JWT Authentication**: Issue JSON Web Tokens for session management.\n- **Email Verification**: Send OTP to users for account verification.\n- **Protected Routes**: Middleware to secure endpoints.\n- **Role-based Access**: User roles (e.g., admin, user).\n- **Password Reset**: OTP-based password reset functionality.\n\n---\n\n## Tech Stack\n\n### Backend\n- **Node.js**: JavaScript runtime for server-side logic.\n- **Express.js**: Web framework for routing and middleware.\n- **MongoDB**: NoSQL database for data storage.\n- **Mongoose**: ODM for MongoDB.\n\n### Security \u0026 Utilities\n- **bcrypt**: Hashing library for password security.\n- **jsonwebtoken**: For issuing and verifying tokens.\n- **Joi**: Schema validation for inputs.\n- **Nodemailer**: For sending emails.\n- **dotenv**: Environment variable management.\n\n---\n\n## Installation\n\n### Prerequisites\n- Node.js and npm installed.\n- MongoDB installed and running locally or a cloud MongoDB URI.\n\n### Steps\n\n1. **Clone the Repository**\n   ```bash\n   git clone https://github.com/AkashKobal/mern-authentication.git\n   cd mern-authentication\n   ```\n\n2. **Install Dependencies**\n   ```bash\n   npm install\n   ```\n\n3. **Environment Variables**\n   Create a `.env` file in the root directory and configure the following variables:\n   ```\n   MONGO_URI=your-mongo-db-uri\n   JWT_SECRET=your-jwt-secret\n   SENDER_EMAIL=your-email\n   SENDER_PASSWORD=your-email-password\n   NODE_ENV=development\n   ```\n\n4. **Run the Server**\n   ```bash\n   npm run server\n   ```\n\n---\n\n## API Endpoints\n\n### Authentication Routes\n\n- **POST** `http://localhost:5000/api/auth/register`\n  - Registers a new user.\n  - Required Fields: `name`, `email`, `password`.\n\n- **POST** `http://localhost:5000/api/auth/login`\n  - Authenticates an existing user.\n  - Required Fields: `email`, `password`.\n\n- **POST** `http://localhost:5000/api/auth/logout`\n  - Logs out the user by clearing the token.\n\n- **POST** `http://localhost:5000/api/auth/send-otp`\n  - Sends OTP for email verification.\n  - Required Fields: `userId`.\n\n- **POST** `http://localhost:5000/api/auth/verify-otp`\n  - Verifies email using OTP.\n  - Required Fields: `otp`, `userId`.\n\n- **GET** `http://localhost:5000/api/auth/is-authenticated`\n  - Checks if the user is authenticated.\n  - Requires a valid JWT token.\n\n---\n\n## Project Structure\n\n```\n/server\n  |-- /Controllers      # Business logic for routes\n  |-- /Middleware       # Middleware for validation and authentication\n  |-- /Models           # Mongoose schemas for database\n  |-- /Routes           # API endpoints\n  |-- /Config           # Configuration files (e.g., nodemailer, database)\n  |-- server.js         # Main entry point\n```\n\n---\n\n## Middleware\n\n- **Validation Middleware**:\n  - `registerValidation`: Validates user registration inputs.\n  - `loginValidation`: Validates login inputs.\n\n- **Authentication Middleware**:\n  - `userAuth`: Validates JWT tokens and protects routes.\n\n---\n\n## Future Enhancements\n\n- Password reset functionality.\n- Enhanced role-based access control (RBAC).\n- Integration with frontend (React.js).\n- Rate limiting and advanced security features.\n\n---\n\n## Contributing\n\nContributions are welcome! Please fork the repository and submit a pull request for any changes.\n\n---\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).\n\n---\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakashkobal%2Fmern-authentication","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakashkobal%2Fmern-authentication","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakashkobal%2Fmern-authentication/lists"}