{"id":30034773,"url":"https://github.com/invincible1602/authentication-nodejs-and-expressjs","last_synced_at":"2025-08-07T00:51:27.909Z","repository":{"id":305463579,"uuid":"1022940414","full_name":"Invincible1602/Authentication-Nodejs-and-ExpressJs","owner":"Invincible1602","description":null,"archived":false,"fork":false,"pushed_at":"2025-07-20T08:01:35.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-20T09:32:37.383Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Invincible1602.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-20T07:14:52.000Z","updated_at":"2025-07-20T08:01:38.000Z","dependencies_parsed_at":"2025-07-20T09:42:43.685Z","dependency_job_id":null,"html_url":"https://github.com/Invincible1602/Authentication-Nodejs-and-ExpressJs","commit_stats":null,"previous_names":["invincible1602/authentication-nodejs-and-expressjs"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/Invincible1602/Authentication-Nodejs-and-ExpressJs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Invincible1602%2FAuthentication-Nodejs-and-ExpressJs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Invincible1602%2FAuthentication-Nodejs-and-ExpressJs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Invincible1602%2FAuthentication-Nodejs-and-ExpressJs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Invincible1602%2FAuthentication-Nodejs-and-ExpressJs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Invincible1602","download_url":"https://codeload.github.com/Invincible1602/Authentication-Nodejs-and-ExpressJs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Invincible1602%2FAuthentication-Nodejs-and-ExpressJs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269181029,"owners_count":24373850,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-06T02:00:09.910Z","response_time":99,"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":"2025-08-07T00:51:24.456Z","updated_at":"2025-08-07T00:51:27.884Z","avatar_url":"https://github.com/Invincible1602.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# **Secure Authentication System**\n\n## **Overview**\n\nThis system provides secure user authentication using:\n\n* **OTP Verification** (during signup)\n* **JWT Token (via HTTP-Only Cookies)** (for session management)\n* **Middleware** (to protect APIs)\n\n---\n\n## **Process Flow**\n\n### **1️⃣ Signup + OTP Verification**\n\n* User calls **`/signup`** API with name, email, password, and mobile.\n* Server generates a **6-digit OTP** and saves it to `otp.json`.\n* OTP is printed in the **terminal** (simulating SMS/Email delivery).\n* User calls **`/verify-otp`** API to submit the OTP.\n* On success, the OTP is deleted and the user is verified.\n\n---\n\n### **2️⃣ Login \u0026 Session Handling**\n\n* User calls **`/login`** with email/mobile + password.\n* Server creates a **JWT token** and sends it via **HTTP-Only Cookie** named `sessionToken`.\n* This cookie is used for session management in the browser or `curl`.\n\n---\n\n### **3️⃣ Middleware Protection**\n\n* Middleware reads the `sessionToken` cookie.\n* Verifies the JWT.\n* If valid, user can access **protected routes**.\n* If invalid or missing, returns **401 Unauthorized**.\n\n---\n\n## **Password Constraints**\n\nDuring **signup**, passwords must:\n\n* Be **at least 8 characters**\n* Include **1 uppercase**, **1 lowercase**, **1 number**, and **1 special character**\n\nExample valid password:\n`Test@1234`\n\nIf the password is weak, server returns:\n\n```json\n{\"error\":\"Password must be at least 8 characters long, contain uppercase, lowercase, number, and special character.\"}\n```\n\nExample test case for weak password:\n\n```bash\ncurl -X POST http://localhost:3000/signup \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"name\": \"WeakUser\",\n    \"email\": \"weak@example.com\",\n    \"password\": \"12345\",\n    \"mobile\": \"6666666666\"\n  }'\n```\n\n---\n\n## **Test Commands**\n\n### **1️⃣ Signup**\n\n```bash\ncurl -X POST http://localhost:3000/signup \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"name\": \"TestUser\",\n    \"email\": \"test@example.com\",\n    \"password\": \"Test@1234\",\n    \"mobile\": \"9999990000\"\n  }'\n```\n\n---\n\n### **2️⃣ Verify OTP**\n\n(Replace `123456` with the OTP printed in your terminal)\n\n```bash\ncurl -X POST http://localhost:3000/verify-otp \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"identifier\": \"test@example.com\",\n    \"otp\": \"123456\"\n  }'\n```\n\n---\n\n### **3️⃣ Login (Save Cookie)**\n\n```bash\ncurl -X POST http://localhost:3000/login \\\n  -H \"Content-Type: application/json\" \\\n  -c cookies.txt \\\n  -d '{\n    \"identifier\": \"test@example.com\",\n    \"password\": \"Test@1234\"\n  }'\n```\n\n---\n\n### **4️⃣ Access Protected Route**\n\n```bash\ncurl -X GET http://localhost:3000/protected \\\n  -b cookies.txt\n```\n\n---\n\n### **5️⃣ Refresh Token (Dummy Refresh)**\n\n```bash\ncurl -X POST http://localhost:3000/refresh-token \\\n  -H \"Content-Type: application/json\" \\\n  -b cookies.txt \\\n  -d '{\n    \"refreshToken\": \"dummy-refresh-token\"\n  }'\n```\n\n---\n\n## **Summary Table**\n\n| Component  | Purpose                             |\n| ---------- | ----------------------------------- |\n| OTP        | Verifies user during signup         |\n| Cookies    | Maintains session securely          |\n| Middleware | Protects API routes with JWT checks |\n\n---\n\n## **Files Used**\n\n* `users.json` – Stores registered users.\n* `otp.json` – Temporarily stores OTPs.\n\n---\n\n## **Security Notes**\n\n* Cookies are **HTTP-Only** (prevents XSS)\n* JWT is used for **stateless session management**\n* OTP has **5-minute expiry**\n\n---\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finvincible1602%2Fauthentication-nodejs-and-expressjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finvincible1602%2Fauthentication-nodejs-and-expressjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finvincible1602%2Fauthentication-nodejs-and-expressjs/lists"}