{"id":19745402,"url":"https://github.com/btd/connect-session","last_synced_at":"2025-04-30T07:34:19.836Z","repository":{"id":6080922,"uuid":"7307448","full_name":"btd/connect-session","owner":"btd","description":"Connect.js session managment for Rest Api applications","archived":false,"fork":false,"pushed_at":"2012-12-24T17:15:37.000Z","size":108,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-08T01:47:11.739Z","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/btd.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}},"created_at":"2012-12-24T13:17:13.000Z","updated_at":"2016-03-03T00:34:21.000Z","dependencies_parsed_at":"2022-08-25T23:31:58.482Z","dependency_job_id":null,"html_url":"https://github.com/btd/connect-session","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/btd%2Fconnect-session","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/btd%2Fconnect-session/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/btd%2Fconnect-session/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/btd%2Fconnect-session/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/btd","download_url":"https://codeload.github.com/btd/connect-session/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223903025,"owners_count":17222479,"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":"2024-11-12T02:08:10.836Z","updated_at":"2024-11-12T02:08:11.333Z","avatar_url":"https://github.com/btd.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# connect-session\n\nIt is a small project which help organize optional sessions in REST applications that uses connect/express. By default\n connect has only cookie session, that is not applicable and very unconvinient for API projects.\n\n## Usage\n\nGenerally it based on connect session.js code, so configuration and options almost the same.\n\nFor example you have a route that handle session management:\n\nFirst i expect you will made some configuration and create middleware function:\n\n```javascript\n//you config-session.js file\nvar connectSession = require('connect-session'),\n    session = connectSession.session,\n    header = connectSession.header;\n\n\nvar util = require('../lib/utils');\n\n//you should replace this one with other store (but this used by default)\nvar MemoryStore = require('../lib/session/memory');\n\nvar loaders = [\n    header({\n        header: 'X-User-Session' //this used by default, so you can skip this\n    })\n];\n\nvar options = {\n    store: new MemoryStore\n}\n\nmodule.exports.sessionCreate = session(loaders, options);\n\nmodule.exports.sessionLoad = session(loaders, util.merge(options, {\n    generateOnMissingSID: false\n}));\n```\n\n```javascript\n\nvar sessionCreate = require('./config-session').sessionCreate;\n\napp.get('/sessions/new', sessionCreate, function(req, res) {\n    res.json({ sid: req.sessionID});\n})\n```\n\nThis route will return newly created session and initialize session. You should understand that session will be available\n\u003cb\u003eonly in this route\u003c/b\u003e. What happen there:\n\nFirst request will be processed by session middleware (by default it uses `MemoryStore` to store sessions) it will use\nheader loader to try to find session id in default header `'X-User-Session'` (to change this pass in header options { header: 'My-header'}).\nIf session id will not be founded new session will be created and its sid will be returned.\n\nOf course you expect that session will be loaded every time it can be loaded, to make this need to add in app general middleware:\n\n```javascript\nvar sessionLoad = require('./config-session').sessionLoad;\n\n//do not forget add all needed middleware before!!!\napp.use(sessionLoad);\n```\n\n## License \n\n(The MIT License)\n\nCopyright (c) 2012 Bardadym Denis \u0026lt;bardadymchik@gmail.com\u0026gt;\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbtd%2Fconnect-session","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbtd%2Fconnect-session","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbtd%2Fconnect-session/lists"}