{"id":27143377,"url":"https://github.com/dilshodbek-nodejs/single-active-session","last_synced_at":"2026-02-06T13:09:01.271Z","repository":{"id":273223517,"uuid":"919018288","full_name":"dilshodbek-nodejs/Single-Active-Session","owner":"dilshodbek-nodejs","description":"Node.js middleware to enforce single active user sessions using JWT and Redis.","archived":false,"fork":false,"pushed_at":"2025-01-19T15:08:11.000Z","size":3,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-26T15:50:52.974Z","etag":null,"topics":["active-sessions","authorization","middleware","middleware-functions","redis","redis-cache","session","single-active-session"],"latest_commit_sha":null,"homepage":"","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/dilshodbek-nodejs.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":"2025-01-19T13:58:57.000Z","updated_at":"2025-01-28T19:07:14.000Z","dependencies_parsed_at":"2025-01-19T15:41:21.520Z","dependency_job_id":"37ef6da2-f285-4a68-ae28-d1e4673f2b62","html_url":"https://github.com/dilshodbek-nodejs/Single-Active-Session","commit_stats":null,"previous_names":["dilshodbek-yoqubjonov/single-active-session","dilshodbek-nodejs/single-active-session"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dilshodbek-nodejs%2FSingle-Active-Session","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dilshodbek-nodejs%2FSingle-Active-Session/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dilshodbek-nodejs%2FSingle-Active-Session/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dilshodbek-nodejs%2FSingle-Active-Session/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dilshodbek-nodejs","download_url":"https://codeload.github.com/dilshodbek-nodejs/Single-Active-Session/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247805140,"owners_count":20999116,"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":["active-sessions","authorization","middleware","middleware-functions","redis","redis-cache","session","single-active-session"],"created_at":"2025-04-08T08:34:06.899Z","updated_at":"2026-02-06T13:09:01.235Z","avatar_url":"https://github.com/dilshodbek-nodejs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Single Active Session Middleware\n\nThis project implements a **Node.js middleware** that ensures a single active session per user. It validates user tokens using **JWT** and manages sessions with **Redis**. The goal is to restrict a user's account to be active on only one device at a time, enhancing both security and control.\n\n## Technologies Used\n\n - Node.js: Backend server.\n - Express.js: Web framework.\n - Redis: Session management.\n - JWT: User authentication and authorization.\n\n## Features\n\n- Enforces a single active session for each user.\n- Validates JSON Web Tokens (JWT) for authentication.\n- Stores and manages session data in Redis for real-time checks.\n- Automatically logs out previous sessions when a new session is initiated.\n\n## How It Works\n\n1. When a user logs in, a JWT is generated and stored in Redis under a unique key (`user:{id}`).\n2. For every protected route, the middleware checks:\n   - If the provided JWT matches the one stored in Redis.\n   - If they don't match, the user is denied access.\n3. Any new login overwrites the existing token in Redis, effectively invalidating the old session.\n\n## Installation\n\n1. Clone the repository:\n   ```bash\n   git clone https://github.com/dilshodbek-yoqubjonov/single-active-session.git\n   ```\n\n\n## Install dependencies:\n1. Install all needed packeges:\n    ```bash\n    npm install\n    ```\n\n2. Run project with nodemon:\n    ```bash\n    npm run dev\n    ```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdilshodbek-nodejs%2Fsingle-active-session","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdilshodbek-nodejs%2Fsingle-active-session","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdilshodbek-nodejs%2Fsingle-active-session/lists"}