/logout Command#
The /logout
command allows users to securely end their current session and disconnect from their CopperX account.Command Overview#
Purpose: Log out from the CopperX account
Authentication Required: Yes (but handled gracefully if not authenticated)
Implementation File: src/bot/handlers/logout.handler.ts
Functionality#
When a user sends the /logout
command, the bot:1.
Checks if the user is currently authenticated
2.
If authenticated, terminates the session and removes authentication tokens
3.
Unsubscribes the user from real-time notifications
4.
Confirms the logout to the user
5.
If not authenticated, informs the user they're not currently logged in
Response Examples#
Successful Logout#
You have been logged out successfully.
Not Logged In#
You're not currently logged in.
Implementation Details#
The logout handler is implemented as follows:Auth Service Logout Method#
The logout functionality relies on the logout
method in the AuthService:Session Management#
The logout process updates the user session to:1.
Set the state to UserState.IDLE
2.
Clear the KYC verification flag
3.
Remove the organization ID
4.
Remove all authentication data (tokens, expiry, etc.)
Notification Management#
The logout process also unsubscribes the user from real-time notifications:Security Considerations#
All authentication tokens are removed from the session
Pusher subscription is terminated to prevent further real-time updates
Redis session is updated but not deleted to maintain user preferences
No personal data is retained in the session after logout
src/services/auth.service.ts
- Contains the logout method
src/services/notification.service.ts
- Contains the unsubscribe method
src/utils/session/session.service.ts
- Manages the user session
src/types/session.types.ts
- Defines the session structure and states
Best Practices#
The logout command is always available, regardless of authentication state
It provides clear feedback about the current status
It cleans up all resources (tokens, subscriptions) to prevent lingering connections
It handles errors gracefully to ensure the user is always logged out, even if some cleanup steps fail
Modified at 2025-03-23 17:07:15