{"id":28684877,"url":"https://github.com/node-modules/userauth","last_synced_at":"2025-06-14T03:07:26.153Z","repository":{"id":5591802,"uuid":"6798296","full_name":"node-modules/userauth","owner":"node-modules","description":"user auth abstraction layer middleware.","archived":false,"fork":false,"pushed_at":"2023-01-09T20:17:57.000Z","size":86,"stargazers_count":1,"open_issues_count":1,"forks_count":2,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-06-11T06:56:30.169Z","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/node-modules.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-11-21T15:50:08.000Z","updated_at":"2023-07-12T08:54:21.000Z","dependencies_parsed_at":"2023-01-13T13:36:49.914Z","dependency_job_id":null,"html_url":"https://github.com/node-modules/userauth","commit_stats":null,"previous_names":["node-modules/userauth"],"tags_count":25,"template":false,"template_full_name":null,"purl":"pkg:github/node-modules/userauth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-modules%2Fuserauth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-modules%2Fuserauth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-modules%2Fuserauth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-modules%2Fuserauth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/node-modules","download_url":"https://codeload.github.com/node-modules/userauth/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-modules%2Fuserauth/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259752078,"owners_count":22905972,"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":[],"created_at":"2025-06-14T03:07:24.129Z","updated_at":"2025-06-14T03:07:26.141Z","avatar_url":"https://github.com/node-modules.png","language":"JavaScript","readme":"# userauth\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Test coverage][coveralls-image]][coveralls-url]\n[![Gittip][gittip-image]][gittip-url]\n[![David deps][david-image]][david-url]\n\n[npm-image]: https://img.shields.io/npm/v/userauth.svg?style=flat\n[npm-url]: https://npmjs.org/package/userauth\n[travis-image]: https://img.shields.io/travis/node-modules/userauth.svg?style=flat\n[travis-url]: https://travis-ci.org/node-modules/userauth\n[coveralls-image]: https://img.shields.io/coveralls/node-modules/userauth.svg?style=flat\n[coveralls-url]: https://coveralls.io/r/node-modules/userauth?branch=master\n[gittip-image]: https://img.shields.io/gittip/fengmk2.svg?style=flat\n[gittip-url]: https://www.gittip.com/fengmk2/\n[david-image]: https://img.shields.io/david/node-modules/userauth.svg?style=flat\n[david-url]: https://david-dm.org/node-modules/userauth\n\n![logo](https://raw.github.com/node-modules/userauth/master/logo.png)\n\n`connect` or `express` user auth abstraction layer middleware.\n\n## Install\n\n```bash\n$ npm install userauth --save\n```\n\n## Usage\n\n`userauth` is dependent on `connect.session()` and `connect.query()`.\n\n```js\nvar connect = require('connect');\nvar userauth = require('userauth');\n\nvar app = connect(\n  connect.cookieParser(),\n  connect.session({\n    secret: 'i m secret'\n  }),\n  connect.query(),\n  // /user* all these urls must login first\n  userauth(/^\\/user/i, {\n    // auth system login url\n    loginURLForamter: function (url) {\n      return 'http://login.demo.com/login?redirect=' + url;\n    },\n    // login callback and getUser info handler\n    getUser: function (req, callback) {\n      var token = req.query.token;\n      proxy.checkToken(token, function (err, info) {\n        if (err) {\n          return callback(err);\n        }\n        callback(null, info);\n      });\n    },\n  })\n);\n```\n\n### Arguments\n\n```js\n/**\n * User auth middleware.\n *\n * @param {Regex|Function(pathname, req)} match, detect which url need to check user auth.\n * @param {Object} [options]\n *  - {Function(url, rootPath)} loginURLForamter, format the login url.\n *  - {String} [rootPath], custom app url root path, default is '/'.\n *  - {String} [loginPath], default is '/login'.\n *  - {String} [loginCallbackPath], default is `options.loginPath + '/callback'`.\n *  - {String} [logoutPath], default is '/logout'.\n *  - {String} [userField], logined user field name on `req.session`, default is 'user', `req.session.user`.\n *  - {Function(req, callback)} getUser, get user function, must get user info with `req`.\n *  - {Function(req, user, callback)} [loginCallback], you can handle user login logic here.\n *    - {Function(err, user, redirectURL)} callback\n *  - {Function(req)} [loginCheck], return true meaning logined. default is `true`.\n *  - {Function(req, res, user, callback)} [logoutCallback], you can handle user logout logic here.\n *    - {Function(err, redirectURL)} callback\n * @return {Function(req, res, next)} userauth middleware\n * @public\n */\nfunction userauth(match, options);\n```\n\n## Login flow\n\n```js\n/**\n * login flow:\n *\n * 1. unauth user, redirect to `$loginPath?redirect=$currentURL`\n * 2. user visit `$loginPath`, redirect to `options.loginURLForamter()` return login url.\n * 3. user visit $loginCallbackPath, handler login callback logic.\n * 4. If user login callback check success, will set `req.session[userField]`,\n *    and redirect to `$currentURL`.\n * 5. If login check callback error, next(err).\n * 6. user visit `$logoutPath`, set `req.session[userField] = null`, and redirect back.\n */\n```\n\n## License\n\n(The MIT License)\n\nCopyright (c) 2012 - 2014 fengmk2 \u003cfengmk2@gmail.com\u003e other contributors.\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnode-modules%2Fuserauth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnode-modules%2Fuserauth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnode-modules%2Fuserauth/lists"}