Overview
The Driver Auth Gateway (/drivers namespace) handles authentication events for driver sessions, including login notifications, session refreshes, and forced disconnections.
Gateway Configuration
Connection Authentication
Handshake Flow
When a driver connects, the gateway performs these validations:Client Connection Example
Outbound Events (Server → Driver)
auth:logged_in
Notifies the driver about a successful login (if they already have active sockets).
Payload:
auth:session_refreshed
Notifies when a session token has been refreshed. The old session is disconnected.
Payload:
auth:session_revoked
Notifies when a session has been revoked (e.g., logout, security event). The socket is forcefully disconnected.
Payload:
admin:auth:user_logged_in
Broadcast to admin clients when any user logs in (monitoring purposes).
Payload:
Disconnection
Client Disconnection
Client Example
Complete Client Example
Security Considerations
Token Validation
- JWT tokens are verified using
TokenService.verifyAccessToken() - Both
sub(user ID) andsid(session ID) must be present in the token - User must exist, be active, and have type
DRIVER - Session must not be revoked and access token must not be expired
Forced Disconnection Scenarios
- Session Refresh: Old session sockets are disconnected when token is refreshed
- Session Revocation: All sockets for a session are disconnected when it’s revoked
- Manual Logout: Server can trigger disconnection via
disconnectSid(sid)method
Room-Based Access Control
Sockets are automatically joined to:driver:{userId}- User-specific eventssession:{sid}- Session-specific control (disconnection)
Next Steps
Driver Availability
Learn about driver status and location events
Connection Setup
General WebSocket connection guide
