{"id":15184793,"url":"https://github.com/githubak2002/ak_adv_auth_jwt","last_synced_at":"2026-02-28T23:02:45.350Z","repository":{"id":257307367,"uuid":"857879049","full_name":"Githubak2002/ak_adv_auth_JwT","owner":"Githubak2002","description":"Full Stack advance auth using JWT, Node js and Zustand for state management ","archived":false,"fork":false,"pushed_at":"2024-10-11T08:06:37.000Z","size":7819,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-08T05:36:16.949Z","etag":null,"topics":["authentication","authorization","jwt","mern-stack","tailwindcss","zustand"],"latest_commit_sha":null,"homepage":"https://ak-adv-auth.onrender.com","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/Githubak2002.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}},"created_at":"2024-09-15T20:51:28.000Z","updated_at":"2024-10-30T05:03:54.000Z","dependencies_parsed_at":"2024-10-11T08:41:23.484Z","dependency_job_id":"a5c1b354-9773-44ac-b5f6-6b2261fae669","html_url":"https://github.com/Githubak2002/ak_adv_auth_JwT","commit_stats":null,"previous_names":["githubak2002/ak_adv_auth_jwt"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Githubak2002%2Fak_adv_auth_JwT","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Githubak2002%2Fak_adv_auth_JwT/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Githubak2002%2Fak_adv_auth_JwT/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Githubak2002%2Fak_adv_auth_JwT/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Githubak2002","download_url":"https://codeload.github.com/Githubak2002/ak_adv_auth_JwT/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240689210,"owners_count":19841891,"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","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":["authentication","authorization","jwt","mern-stack","tailwindcss","zustand"],"created_at":"2024-09-27T17:23:32.589Z","updated_at":"2026-02-28T23:02:45.306Z","avatar_url":"https://github.com/Githubak2002.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Project README\n\n## Features\n\n- **Authentication \u0026 Authorization**\n  - JWT (JSON Web Tokens)\n  - User Authentication\n  - User Authorization\n\n- **Technology Stack**\n  - MERN Stack (MongoDB, Express, React, Node.js)\n  - Tailwind CSS\n  - Zustand (State Management)\n\n- **Functionality**\n  - Email Verification\n  - Error Handling\n  - Forgot Password \u0026 Password Reset\n  - Signup, Login, and Logout Endpoints\n  - Check Auth Endpoint\n  - Sending Verification Emails\n\n- **Frontend Setup**\n  - Signup and Login Page UI\n  - Implementing Signup\n  - Implementing Email Verification\n  - Protecting Routes\n  - Implementing Login\n  - Implementing Forgot Password\n\n## To-Do\n- Integrate Jest or React Testing Library for testing\n- Add delete account confirmation/popup button\n\n---\n\n## NPM Package Details\n\n- **cookie-parser**: Middleware to parse cookies\n- **jsonwebtoken**: For generating and verifying JSON Web Tokens (JWTs)\n- **dotenv**: For managing environment variables\n- **express**: A web framework for Node.js\n- **bcryptjs**: For hashing passwords\n- **mongoose**: An Object Data Modeling (ODM) library for MongoDB\n- **nodemon**: Automatically restarts the server when file changes are detected\n- **mailtrap**: For testing email sending (if using Mailtrap)\n- **crypto**: Built-in package for cryptographic functions\n  - `randomInt(10, 20)`\n  - `randomBytes(20).toString('hex')`\n\n---\n\n## JWT Methods\n\n1. **`jwt.sign(payload, secretOrPrivateKey, options)`**\n   - **Purpose**: Create a new JWT.\n   - **Parameters**:\n     - `payload`: Data to include in the token (e.g., user ID, roles).\n     - `secretOrPrivateKey`: Secret key to sign the token.\n     - `options`: Optional settings (e.g., expiration time).\n   - **Usage**: Generate a token to send to clients or store for later use.\n   - **Example**:\n     ```javascript\n     const token = jwt.sign({ userId: '1234' }, 'your-secret-key', { expiresIn: '1h' });\n     ```\n\n2. **`jwt.verify(token, secretOrPublicKey, options, callback)`**\n   - **Purpose**: Check if a JWT is valid and decode it.\n   - **Parameters**:\n     - `token`: The JWT to verify.\n     - `secretOrPublicKey`: Key used to sign the token for verification.\n     - `options`: Optional settings (e.g., expected audience).\n     - `callback`: Function called with verification result or error.\n   - **Usage**: Verify token validity and extract payload if valid.\n   - **Example**:\n     ```javascript\n     jwt.verify(token, 'your-secret-key', (err, decoded) =\u003e {\n       if (err) {\n         console.error('Invalid token');\n       } else {\n         console.log('Decoded payload:', decoded);\n       }\n     });\n     ```\n\n3. **`jwt.decode(token, options)`**\n   - **Purpose**: Decode a JWT without verifying its signature.\n   - **Parameters**:\n     - `token`: The JWT to decode.\n     - `options`: Optional settings (e.g., whether to get header or payload).\n   - **Usage**: Extract and view token payload without validation. Useful for debugging.\n   - **Example**:\n     ```javascript\n     const decoded = jwt.decode(token);\n     console.log('Decoded payload:', decoded);\n     ```\n\n---\n\n## Zustand Store Usage\n\n- **Updating State**:\n  ```javascript\n  useAuthStore.setState({ forgotPassPopup: true });\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithubak2002%2Fak_adv_auth_jwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgithubak2002%2Fak_adv_auth_jwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithubak2002%2Fak_adv_auth_jwt/lists"}