Skip to main content
Protect your realtime endpoints with custom auth logic.

Basic Middleware

api/realtime/route.ts

Middleware API

The middleware function receives:
request
Request
The incoming HTTP Request object
channels
string[]
default:"['default']"
The channels a user is attempting to connect to
return
  • Return undefined or nothing to allow the connection
  • Return a Response object to block the connection with a custom error

Authentication Patterns

Verify users can access specific channels:
api/realtime/route.ts
Verify user sessions before allowing connections:
api/realtime/route.ts
Control access based on user roles:
api/realtime/route.ts