Socket.io authentication middleware using JSON Web Tokens (JWT). Current stable version is 0.2.0. This package provides a simple way to authenticate Socket.io connections by verifying a JWT token passed as a query parameter (or auth object for Socket.io v3+). It supports custom secret, algorithm selection, and optional succeedWithoutToken mode for guest connections. The package is designed for Socket.io >= 1.0 and is commonly used to protect WebSocket endpoints. Unlike more modern alternatives like socketio-jwt (which is more actively maintained), socketio-jwt-auth has a simple API but has not seen updates since 2018.
npm install socketio-jwt-authVerified import paths — ran on the pinned version, not inferred.
Shows how to set up Socket.io server with JWT authentication middleware and client connection with token.
Use auth: { token: '...' } instead of query: 'auth_token=...'.Consider migrating to socketio-jwt (if using Socket.io v2) or implementing custom JWT verification.
Always check if payload exists before accessing properties: if (payload && payload.sub) { ... }Always ensure the client sends the token properly via query/auth.
Use const jwtAuth = require('socketio-jwt-auth'); then jwtAuth.authenticate(...).Generate tokens with a suitable expiration (e.g., '1h') and refresh token logic on client.
Ensure client and server use the same algorithm (e.g., HS256, RS256).