Skip to content

Authentication

The user app implements a secure authentication system with multiple entry points and verification methods.

Authentication Flows

Registration Flow

New users can register using their phone number:

┌─────────────────┐
│  Enter Phone    │
│    Number       │
└────────┬────────┘


┌─────────────────┐
│  Receive OTP    │
│  (WhatsApp/SMS) │
└────────┬────────┘


┌─────────────────┐
│  Verify OTP     │
│                 │
└────────┬────────┘


┌─────────────────┐
│  Create PIN     │
│   (4-6 digits)  │
└────────┬────────┘


┌─────────────────┐
│  Profile Setup  │
│  (Name, Email)  │
└────────┬────────┘


┌─────────────────┐
│  Registration   │
│   Complete      │
└─────────────────┘

Login Flow

Returning users can authenticate via:

  1. PIN Login: Phone number + PIN
  2. Biometric Login: Fingerprint/Face ID (if enabled)
  3. Password Login: Email + Password (optional)
┌─────────────────┐
│  Enter Phone    │
│    Number       │
└────────┬────────┘


┌─────────────────┐     ┌─────────────────┐
│   Enter PIN     │────▶│   Biometric     │
│                 │     │   (Optional)    │
└────────┬────────┘     └────────┬────────┘
         │                       │
         └───────────┬───────────┘

            ┌─────────────────┐
            │   Home Screen   │
            └─────────────────┘

Forgot Password Flow

┌─────────────────┐
│  Enter Phone    │
│    Number       │
└────────┬────────┘


┌─────────────────┐
│  Receive OTP    │
│                 │
└────────┬────────┘


┌─────────────────┐
│  Verify OTP     │
│                 │
└────────┬────────┘


┌─────────────────┐
│  Create New     │
│     PIN         │
└────────┬────────┘


┌─────────────────┐
│  Confirm New    │
│     PIN         │
└─────────────────┘

Controller Methods

MethodDescription
login(phone, pin)Authenticate with phone and PIN
register(phone, otp)Register new user after OTP verification
verifyOtp(otp)Verify OTP code
resetPin(newPin)Reset user PIN
logout()End user session

Service Methods

MethodDescription
login(phone, pin)Returns AuthResponse
sendOtp(phone)Send OTP to phone
verifyOtp(phone, otp)Verify OTP, returns boolean
register(request)Complete registration
refreshToken()Refresh JWT token

API Endpoints

EndpointMethodDescription
/auth/loginPOSTUser login
/auth/registerPOSTNew user registration
/auth/send-otpPOSTRequest OTP
/auth/verify-otpPOSTVerify OTP code
/auth/reset-pinPOSTReset user PIN
/auth/refreshPOSTRefresh JWT token

OTP Configuration

SettingValue
Primary ChannelWhatsApp (requires button URL)
FallbackSMS via Twilio
Expiry5 minutes
Max Attempts3

Security Measures

Token Storage

Tokens are stored securely using FlutterSecureStorage:

KeyDescription
access_tokenJWT access token
refresh_tokenJWT refresh token

Biometric Authentication

Biometric login can be enabled after initial setup:

  • Uses LocalAuthentication package
  • Checks device capability first
  • Saves preference after successful setup

Error Handling

Error CodeMessageAction
AUTH_001Invalid credentialsShow error, clear PIN
AUTH_002Account lockedContact support
AUTH_003OTP expiredRequest new OTP
AUTH_004Too many attemptsWait 15 minutes
AUTH_005Session expiredRe-authenticate
FilePurpose
lib/screens/auth/login_screen.dartLogin screen
lib/screens/auth/register_screen.dartRegistration screen
lib/screens/auth/otp_verification_screen.dartOTP verification
lib/screens/auth/forgot_password_screen.dartPassword reset
lib/controllers/auth_controller.dartAuth controller
lib/services/auth_service.dartAuth service

Internal use only - Keshless Payment Platform