{"id":15007601,"url":"https://github.com/alwinsimon/base-auth-handler-npm-module","last_synced_at":"2026-03-14T16:08:34.306Z","repository":{"id":207568877,"uuid":"718980713","full_name":"alwinsimon/base-auth-handler-npm-module","owner":"alwinsimon","description":"A simple authentication handling module for Express written in TypeScript. Provides middlewares for managing user authentication with JWT.","archived":false,"fork":false,"pushed_at":"2023-11-28T18:28:45.000Z","size":113,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-18T16:18:06.349Z","etag":null,"topics":["auth","authentication","authorization","cookie-jwt","data-validation","expressjs","jwt","nodejs","npm-module","npmjs"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/base-auth-handler","language":"TypeScript","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/alwinsimon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2023-11-15T07:34:34.000Z","updated_at":"2023-11-28T19:07:18.000Z","dependencies_parsed_at":"2023-11-28T19:34:47.810Z","dependency_job_id":null,"html_url":"https://github.com/alwinsimon/base-auth-handler-npm-module","commit_stats":{"total_commits":16,"total_committers":1,"mean_commits":16.0,"dds":0.0,"last_synced_commit":"d9eb0f39a37a8dd62c95f93467ff88751fd8dc0f"},"previous_names":["alwinsimon/auth-npm-module","alwinsimon/base-auth-handler-npm-module"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alwinsimon%2Fbase-auth-handler-npm-module","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alwinsimon%2Fbase-auth-handler-npm-module/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alwinsimon%2Fbase-auth-handler-npm-module/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alwinsimon%2Fbase-auth-handler-npm-module/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alwinsimon","download_url":"https://codeload.github.com/alwinsimon/base-auth-handler-npm-module/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243165538,"owners_count":20246725,"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":["auth","authentication","authorization","cookie-jwt","data-validation","expressjs","jwt","nodejs","npm-module","npmjs"],"created_at":"2024-09-24T19:12:04.844Z","updated_at":"2025-12-25T16:35:43.002Z","avatar_url":"https://github.com/alwinsimon.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# base-auth-handler  [![npm version](https://badge.fury.io/js/base-auth-handler.svg)](https://www.npmjs.com/package/base-auth-handler)\n\n## A simple authentication handling module for Express written in TypeScript.\n\n\n### Provides middlewares for managing user authentication with JWT.\n\n## Features\n\n- Written in TypeScript\n- Published as both JS and TypeScript types\n- Handles user authentication with JSON Web Tokens\n- Provides middlewares for Express apps\n- Easy to integrate\n\n## Installation\n\n```\nnpm install base-auth-handler\n```\n\n## Usage\n\nImport the middlewares you need:\n\n```ts\nimport { currentUser, requireAuth, validateRequest } from \"base-auth-handler\";\n```\n\n### currentUser\n\nPopulates `req.currentUser` if a valid JWT token cookie exists.\n\n```ts \napp.use(currentUser);\n```\n\n### requireAuth \n\nThrows error if current user is not authenticated. Use to protect routes.\n\n```ts\napp.get(\"/profile\", requireAuth, (req, res) =\u003e {\n  // can access req.currentUser\n});\n```\n\n### validateRequest\n\nValidates request using express-validator. Useful for validating sign up data.\n\n```ts\napp.post(\"/signup\", validators, validateRequest, (req, res) =\u003e {\n  // data has been validated\n})\n```\n\n## Example App\n\n```ts\nimport express from \"express\";\nimport cookieParser from \"cookie-parser\";\n\nimport { currentUser, requireAuth, validateRequest } from \"base-auth-handler\";\n\nconst app = express();\n\napp.use(cookieParser());\n\napp.get(\"/profile\", currentUser, requireAuth, (req, res) =\u003e {\n  res.send(req.currentUser);  \n});\n\napp.post(\"/signup\", \n  [\n    // validators\n  ], \n  validateRequest,\n  (req, res) =\u003e {\n    // create user\n  }\n);\n```\n\nThe middlewares handle user authentication and validation - the app code stays clean.\n\n## Contributing  \nFeel free to contribute to this project by reporting issues or creating pull requests. For major changes, please open an issue first to discuss the proposed changes.\n\n## License  \nThis module is licensed under the MIT License - see the LICENSE file for details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falwinsimon%2Fbase-auth-handler-npm-module","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falwinsimon%2Fbase-auth-handler-npm-module","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falwinsimon%2Fbase-auth-handler-npm-module/lists"}