Module auth

Module auth 

Source
Expand description

Authentication state tracking for WebSocket clients.

This module provides a robust authentication tracker that coordinates login attempts and ensures each attempt produces a fresh success or failure signal before operations resume. It follows a proven pattern used in production.

§Key Features

  • Oneshot signaling: Each auth attempt gets a dedicated channel for result notification.
  • Superseding logic: New authentication requests cancel pending ones.
  • Timeout handling: Configurable timeout for authentication responses.
  • Generic error mapping: Adapters can map to their specific error types.

Based on production usage, the recommended pattern is:

  1. Authentication guard: Maintain Arc<AtomicBool> to track auth state separately from tracker.
  2. Guard checks: Check guard before all private operations (orders, cancels, etc.).
  3. Reconnection flow: Authenticate BEFORE resubscribing to topics.
  4. Event propagation: Send auth failures through event channels to consumers.
  5. State lifecycle: Clear guard on disconnect, set on auth success.

Structs§

AuthTracker
Generic authentication state tracker for WebSocket connections.

Type Aliases§

AuthResultReceiver
AuthResultSender