Registry / security / ws-user

ws-user

JSON →
library1.0.0-rc.3jsnpmunverified

ws-user v1.0.0-rc.3 provides user authentication and authorization tailored for WebSocket applications. It offers registration, login, logout, and password/email management with WebSocket-native patterns. Unlike generic auth libraries, it integrates directly with WebSocket lifecycle events. As a release candidate, the API is stable but may see minor changes before v1.0.0. Development appears active on GitHub, with releases on npm.

npm install ws-user
INSTALL
IMPORT
SIG · WS-USER
W
ws-user
securityjavascriptv1.0.0-rc.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createUserApp
import { createUserApp } from 'ws-user'
const createUserApp = require('ws-user')
ESM-only package; CommonJS require is not supported.
User
import { User } from 'ws-user'
import User from 'ws-user'
User is a named export, not default.
authenticate
import { authenticate } from 'ws-user'
Utility for middleware; can also be imported as part of createUserApp.

Sets up a WebSocket server with user registration, login, and logout using ws-user. Demonstrates createUserApp and basic message handling.

import { createUserApp } from 'ws-user'; import WebSocket from 'ws'; const app = createUserApp({ jwtSecret: process.env.JWT_SECRET ?? 'changeme', database: 'sqlite://users.db' }); const wss = new WebSocket.Server({ port: 8080 }); wss.on('connection', (ws, req) => { ws.on('message', async (message) => { const data = JSON.parse(message.toString()); if (data.type === 'register') { const result = await app.register(ws, data.email, data.password); ws.send(JSON.stringify({ type: 'registered', ...result })); } else if (data.type === 'login') { const result = await app.login(ws, data.email, data.password); ws.send(JSON.stringify({ type: 'loggedIn', ...result })); } else if (data.type === 'logout') { await app.logout(ws); ws.send(JSON.stringify({ type: 'loggedOut' })); } }); }); console.log('WebSocket server with auth on ws://localhost:8080');
Debug
Known issues
breakingv1.0.0-rc.3 is a release candidate; API may change before stable release.
fix
Pin to exact version and test before upgrading.
affects: <=1.0.0-rc.3
gotchaThe 'database' option defaults to an in-memory store; for production, provide persistent database connection string.
fix
Set database: process.env.DATABASE_URL || 'sqlite://prod.db'
affects: >=1.0.0-rc.1
deprecatedThe 'authenticate' middleware will be renamed to 'withAuth' in v2.
fix
Use authenticate for now, but plan migration.
affects: >=1.0.0-rc.1
gotchaWebSocket library must be explicitly passed; ws-user does not bundle it.
fix
Install 'ws' or 'uws' separately.
affects: >=1.0.0-rc.1
breakingRegister / login API changed from callback-based to promise-based in v0.9.0.
fix
Migrate to async/await pattern.
affects: <1.0.0-rc.1
Errors
Common errors & fixes
Error: ws is not defined
WebSocket library missing or not imported
fix
Install ws: npm install ws and import WebSocket from 'ws'
TypeError: app.register is not a function
createUserApp not called or misconfigured
fix
Ensure createUserApp returns an object with register, login, etc. Check import
Error: Invalid JWT secret
Missing or weak jwtSecret in configuration
fix
Set a strong JWT_SECRET environment variable
Module not found: Can't resolve 'ws-user'
Package not installed or wrong import path
fix
npm install ws-user@rc
Upgrade
Version history
1.0.0-rc.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
29 hits · last 30 days
node
26
Resources
ws-user — npm install ws-user · libregistry