{"id":22010285,"url":"https://github.com/sakalx/redux-socket-auth-middleware","last_synced_at":"2026-05-04T00:32:59.278Z","repository":{"id":57351614,"uuid":"175886819","full_name":"sakalx/redux-socket-auth-middleware","owner":"sakalx","description":"Redux socket authentication middleware","archived":false,"fork":false,"pushed_at":"2019-03-25T19:59:40.000Z","size":294,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-03-25T09:03:40.904Z","etag":null,"topics":["auth","authentication","authorization","authorization-middleware","middleware","redux-middleware","socket-io"],"latest_commit_sha":null,"homepage":"https://socketio-auth.herokuapp.com","language":"JavaScript","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/sakalx.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}},"created_at":"2019-03-15T20:28:48.000Z","updated_at":"2020-04-27T04:11:15.000Z","dependencies_parsed_at":"2022-09-19T00:02:21.296Z","dependency_job_id":null,"html_url":"https://github.com/sakalx/redux-socket-auth-middleware","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sakalx/redux-socket-auth-middleware","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakalx%2Fredux-socket-auth-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakalx%2Fredux-socket-auth-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakalx%2Fredux-socket-auth-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakalx%2Fredux-socket-auth-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sakalx","download_url":"https://codeload.github.com/sakalx/redux-socket-auth-middleware/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakalx%2Fredux-socket-auth-middleware/sbom","scorecard":{"id":796035,"data":{"date":"2025-08-11","repo":{"name":"github.com/sakalx/redux-socket-auth-middleware","commit":"d92f3a7ad63ab133fa92a8df028c018e2667aff6"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-23T08:59:11.617Z","repository_id":57351614,"created_at":"2025-08-23T08:59:11.617Z","updated_at":"2025-08-23T08:59:11.617Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32590275,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T22:12:39.696Z","status":"ssl_error","status_checked_at":"2026-05-03T22:09:10.534Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","authorization-middleware","middleware","redux-middleware","socket-io"],"created_at":"2024-11-30T02:12:35.136Z","updated_at":"2026-05-04T00:32:59.258Z","avatar_url":"https://github.com/sakalx.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Redux socket.io authentication middleware\n ____________________________________________________\n**Redux middleware for handle [socket.io](https://socket.io/) authentication.**\n\nInspiration from [redux-promise-middleware.](https://www.npmjs.com/package/redux-promise-middleware)\n____________________________________________________\n[Demo project: chat with authentication](https://socketio-auth.herokuapp.com)\n\n### [Where should websockets and other persistent connections live?](https://redux.js.org/faq/code-structure#where-should-websockets-and-other-persistent-connections-live)\n\n\u003e Middleware are the right place for persistent connections like websockets in a Redux app, for several reasons:\n\u003e * Middleware exist for the lifetime of the application\n\u003e * Like with the store itself, you probably only need a single instance of a given connection that the whole app can use\n\u003e * Middleware can see all dispatched actions and dispatch actions themselves. This means a middleware can take dispatched actions and turn those into messages sent over the websocket, and dispatch new actions when a message is received over the websocket.\n\n____________________________________________________\n\n Given a single action with a socketIOClient.connect payload,\n the middleware transforms the action to a separate a pending action\n and a separate connected/rejected/disconnected action.\n \n```javascript\n  import socketIOClient from 'socket.io-client';\n    \n  export const connectingToServer = () =\u003e ({\n      type: 'SOCKET',\n      payload: socketIOClient.connect(uri, opts),\n    });\n```\n____________________________________________________\n\n## Installation\nFirst, install the middleware:\n\n`npm i -S redux-socket-auth-middleware`\n\n## Setup Store\nImport the middleware \nand include it in applyMiddleware when creating the Redux store:\n\n**[TIP]** You can also add [redux-logger](https://www.npmjs.com/package/redux-logger) middleware.\n\n```javascript\n  import {applyMiddleware, createStore} from 'redux';\n  import socketAuth from 'redux-socket-auth-middleware';\n  import logger from 'redux-logger';\n  \n  // Take our rootReducer/appReducer.\n  import rootReducer from './reducers';\n  \n  // Apply middlewares, logger always in the end.\n  const middleware = applyMiddleware(socketAuth, logger);\n  \n  // Create store with reducers and middlewares.\n  const store = createStore(rootReducer, middleware);\n  \n  // Now we can use store in App\n  export default store;\n```   \n\n## Action\nDispatch a socketIOClient.connect as the value of the payload property of the action.\n```javascript\n  import socketIOClient from 'socket.io-client';\n  \n  // Type of action:\n  const SOCKET = 'SOCKET';\n  \n  // URL where is running a server with socket.io\n  const url = 'http://localhost:8000';\n  \n  // Function for connecting to a server\n  // with that connection we passing query string: user \n  const connect = user =\u003e socketIOClient.connect(url, {query: `user=${user}`});\n  \n  // const user = JSON.stringify({name: 'Soda', password: 'secret'})\n  export const connectingToServer = (user = null) =\u003e ({\n    type: SOCKET,\n    payload: connect(user),\n  });\n  \n    /*  Now we can use this action in App\n    * user argument hold name and password as object string\n    * for adding into connection as query\n    */\n    \n    // That's it for dispatch action!\n```\n\n## Reducer\n\n```javascript\n  // Action types suffixes for socket:\n  const suffix = {\n    PENDING: '_PENDING',\n    CONNECTED: '_CONNECTED',\n    REJECTED: '_REJECTED',\n    DISCONNECTED: '_DISCONNECTED',\n  };\n\n  // Action type that dispatched connectingToServer action\n  const SOCKET = 'SOCKET';\n\n  // Initialization state:\n  const initState = {\n    disconnected: null,\n    error: null,\n    fetching: false,\n    io: null,\n  };\n  \n  // Reducer for handle socket.io connection.\n  export default function socket(state = initState, {type, payload}) {\n    switch (type) {\n  \n      // Handle action socket.io connecting to a server:\n      case SOCKET + suffix.PENDING:\n        return ({\n          ...state,\n          fetching: true,\n        });\n  \n      // Handle action socket.io connected to a server:\n      // payload hold connected socket.io.\n      case SOCKET + suffix.CONNECTED:\n        return ({\n          ...state,\n          io: payload,\n          fetching: false,\n        });\n  \n      // Handle action server rejected connection:\n      // payload hold error from a server.\n      case SOCKET + suffix.REJECTED:\n        return ({\n          ...state,\n          error: payload,\n          fetching: false,\n        });\n  \n      // Handle action server disconnect client-socket:\n      // payload hold reason disconnected from a server.\n      case SOCKET + suffix.DISCONNECTED:\n        return ({\n          ...state,\n          disconnected: payload,\n          fetching: false,\n        });\n    }\n  \n    return state;\n  }\n\n  // That's it!\n```\n\n## APP\n```javascript\n  import React, {useState} from 'react';\n  import {bindActionCreators} from 'redux';\n  import {connect} from 'react-redux';\n  // import redux action function for connecting to server\n  import {connectingToServer} from '../path to redux action connectingToServer';\n  \n  function App({socket, connectingToServer}) {\n    const [name, setName] = useState('');\n    const [password, setPassword] = useState('');\n    \n    const handleChangeName = ({target}) =\u003e setName(target.value);\n    const handleChangePassword = ({target}) =\u003e setPassword(target.value);\n    \n    const handleLogin = () =\u003e {\n        const user = JSON.stringify({name, password});\n        \n        // Dispatch action \n        connectingToServer(user);\n    };\n    \n    const renderStatus = () =\u003e (\n      // If is a socket in redux store and is this socket connected.\n      socket.io \u0026\u0026 socket.io.connected\n        ? 'Connected'\n        : 'Not connected'\n    );\n    \n    // If is fetching from a server? \n    if (socket.fetching) return \u003ch1\u003eLoading...\u003c/h1\u003e\n      \n    return (\n      \u003cdiv\u003e\n        \u003ch1\u003e{renderStatus()}\u003c/h1\u003e\n        \u003cinput value={name} onChange={handleChangeName}/\u003e\n        \u003cinput value={password} onChange={handleChangePassword}/\u003e \n        \u003cbutton onClick={handleLogin}\u003eLogin\u003c/button\u003e\n      \u003c/div\u003e\n    )\n  }\n  \n  const mapStateToProps = ({socket}) =\u003e ({\n    socket,\n  });\n  \n \n  const mapDispatchToProps = dispatch =\u003e bindActionCreators({\n    connectingToServer,\n  }, dispatch);\n  \n  export default connect(mapStateToProps, mapDispatchToProps)(App);\n  \n          /* When we get a connection with a server:\n           * redux store will hold socket.io,\n           * so we can listen or emit events.\n           * socket.io.on('some event', callback)\n           * socket.io.emit('some event', arguments) \n           * just connect redux to component \n           * and mapStateToProps to get access to socket.io\n           */\n```\n____________________________________________________\n\n### [Server-side socket.io authentication](https://socket.io/docs/migrating-from-0-9/)\n\n```javascript\n io.use(function(socket, next) {\n   var handshakeData = socket.request;\n   // make sure the handshake data looks good as before\n   // if error do this:\n     // next(new Error('not authorized'));\n   // else just call next\n   next();\n });\n```\n*[Example of implementation.]( https://github.com/sakalx/redux-socket-auth-middleware/tree/example-chat)*\n \n ____________________________________________________\n \n### Issues\n For bug reports and feature requests, file an issue on [GitHub.](https://github.com/sakalx/redux-socket-auth-middleware/issues/new)\n ____________________________________________________\n \n### License\n  [Code licensed with the MIT License (MIT).](https://github.com/sakalx/redux-socket-auth-middleware/blob/master/LICENSE)\n ____________________________________________________\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsakalx%2Fredux-socket-auth-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsakalx%2Fredux-socket-auth-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsakalx%2Fredux-socket-auth-middleware/lists"}