/login Command#
The /login
command allows users to authenticate with their CopperX account through a secure email OTP (One-Time Password) process.Command Overview#
Purpose: Authenticate users with their CopperX account
Authentication Required: No
Implementation File: src/bot/handlers/login.handler.ts
Authentication Flow#
The login process follows these steps:1.
User sends /login
command
2.
Bot prompts user to enter their email address
3.
User provides their email address
4.
Bot requests an OTP from the CopperX API
5.
CopperX sends an OTP to the user's email
6.
Bot prompts user to enter the OTP
8.
Bot verifies the OTP with the CopperX API
9.
On success, the bot stores authentication tokens and checks KYC status
Response Examples#
Initial Login Prompt#
🔐 Login to your CopperX account to get started.
Enter your email and an OTP will be sent to your email:
email@example.com
OTP Prompt#
An OTP has been sent to your email. Please enter it to complete your login:
Successful Login (KYC Verified)#
✅ Login successful! Welcome, username!
You can now use the following commands:
• /wallet - Check your wallet balance
• /send - Send funds to another user
• /logout - Logout from your account
Successful Login (KYC Not Verified)#
✅ Login successful! Welcome, username!
⚠️ Your account KYC is not verified. Please complete your KYC verification to use all features.
With inline keyboard buttons:Learn how to complete KYC
Implementation Details#
Login Handler#
The login handler initializes the email input process:When the user provides their email address:OTP Verification#
When the user provides the OTP:Auth Service#
The login handler relies on the AuthService
to interact with the CopperX API:Session States#
The login process uses the following session states:UserState.AWAITING_LOGIN_EMAIL
: Waiting for the user to provide their email
UserState.AWAITING_OTP
: Waiting for the user to provide the OTP
UserState.AUTHENTICATED
: User has successfully authenticated
The login handler includes validation for:Email format using a regular expression: /^[^\s@]+@[^\s@]+\.[^\s@]+$/
OTP format using a regular expression: /^\d{4,6}$/
Error Handling#
The login process handles various error scenarios:Failed OTP request (e.g., email not registered)
src/bot/messages/start.messages.ts
- Contains login message templates
src/types/session.types.ts
- Defines session states and structure
src/utils/copperxApi/copperxApi.auth.ts
- API client for authentication
src/services/auth.service.ts
- Authentication service
Security Considerations#
OTP is sent directly to the user's email, not through Telegram
Session IDs (sid) are securely stored and used only for the current authentication flow
Access tokens have an expiration time
Rate limiting is applied to prevent brute force attacks
Modified at 2025-03-23 17:07:05