Basic Middleware
api/realtime/route.ts
Middleware API
The middleware function receives:The incoming HTTP Request object
The channels a user is attempting to connect to
return
- Return
undefinedor nothing to allow the connection - Return a
Responseobject to block the connection with a custom error
Authentication Patterns
User-Based Auth
User-Based Auth
Verify users can access specific channels:
api/realtime/route.ts
Session-Based Auth
Session-Based Auth
Verify user sessions before allowing connections:
api/realtime/route.ts
Role-Based Access
Role-Based Access
Control access based on user roles:
api/realtime/route.ts