websocket

Scaffold secure WebSocket gateways with JWT auth and RabbitMQ broadcasting.

Updated Apr 6, 2026
One-click install
npx skills add https://github.com/lety-ai/lety-skill-hub --skill websocket-lety-ai
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: websocket
Source: https://github.com/lety-ai/lety-skill-hub/tree/main/plugins/websocket/skills/websocket
Command: npx skills add https://github.com/lety-ai/lety-skill-hub --skill websocket-lety-ai

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Real-time features often rely on fragile, insecure, or ad-hoc socket implementations that leak tenant data, expose tokens in URLs, or mix business logic into gateways; this Skill standardizes secure, production-ready WebSocket patterns so servers can push tenant-scoped events reliably without polling.

Core Features & Use Cases

  • JWT handshake authentication: enforce token verification during the handshake and store verified user/tenant data in socket.data.
  • Tenant room isolation & safe broadcasting: ensure events are emitted only to tenant:<tenantId> rooms to prevent cross-tenant leakage.
  • RabbitMQ consumer → broadcast pattern: consume microservice events, ack on success, nack without requeue on failure to avoid poison messages.
  • Frontend integration: generate a Next.js client hook with socket.io-client and Zustand store wiring for reconnect and auth error handling.
  • Use Case: implement Notifications or Chat where backend microservices publish events to RabbitMQ and the gateway reliably relays them to authenticated tenant clients.

Quick Start

Scaffold a tenant-scoped Notifications WebSocket gateway with JWT handshake auth, a RabbitMQ consumer that broadcasts to tenant rooms, and a Next.js useNotificationsSocket hook integrated with Zustand.

Frequently Asked Questions about websocket

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I authenticate WebSocket connections with JWT in a NestJS gateway?

Authenticate WebSocket connections by verifying the JWT during the handshake using socket.handshake.auth, then storing the verified user and tenant data in socket.data. This approach enforces token verification before the connection establishes and avoids exposing tokens in URLs.

How do I broadcast RabbitMQ events to specific tenants over WebSockets?

Broadcast RabbitMQ events by consuming microservice messages in the gateway and emitting them exclusively to tenant:<tenantId> rooms. On successful broadcast, the consumer acks the message; on failure, it nacks without requeue to prevent poison messages from blocking the queue.

How do I isolate tenant data in a Socket.io gateway to prevent cross-tenant leakage?

Isolate tenant data by enforcing tenant room isolation, ensuring events are emitted only to tenant:<tenantId> rooms. This restricts broadcasts to authenticated clients within the same tenant scope and prevents cross-tenant data leakage.

How do I integrate real-time WebSocket events with Zustand in a Next.js frontend?

Integrate real-time WebSocket events by generating a Next.js client hook using socket.io-client and Zustand store wiring. The hook manages connection states, handles reconnections, and processes authentication errors automatically.

Can I use this WebSocket gateway pattern with polling transports in Socket.io?

No, the gateway restricts connections to websocket-only transports. It also enforces strict CORS by setting the origin to the FRONTEND_URL environment variable, ensuring secure communication without polling fallback.

How do I separate business logic from WebSocket gateway handling in NestJS?

Separate business logic by maintaining a thin gateway/service separation where the WebSocket gateway only handles connection events and message routing. The service layer processes business logic, while RabbitMQ handles the microservice event distribution before broadcasting to clients.