Skip to content

hemantfsu/StapuBox-OTP-App

Repository files navigation

StapuBox - OTP Login App

A React Native mobile application implementing a secure 3-screen OTP authentication flow with SMS auto-read functionality for Android.

πŸ“Έ App Screenshots

The app features a clean, modern interface with three main screens:

Send OTP Screen Verify OTP Screen Success Screen
Enter 10-digit mobile number Auto-read or manually enter 4-digit OTP Login confirmation
Screen 1 Screen 2 Screen 3

🎯 Key Features Shown

  • βœ… Clean, pixel-perfect UI matching Figma designs
  • βœ… Real-time validation with error highlighting
  • βœ… Auto-focus between OTP input fields
  • βœ… SMS auto-read on Android devices
  • βœ… 60-second countdown timer for resend OTP
  • βœ… Smooth animations and transitions

πŸ“± Features

Core Functionality

  • βœ… Screen 1 - Send OTP: Mobile number input with validation (India, 10 digits)
  • βœ… Screen 2 - Verify OTP: 4-digit OTP verification with auto-focus and auto-submit
  • βœ… Screen 3 - Success: Confirmation screen after successful verification

Advanced Features

  • πŸ” SMS Auto-Read (Android) using SMS Retriever API
  • ⏱️ Resend OTP with 60-second cooldown timer
  • 🎨 Pixel-perfect UI based on Figma designs
  • ⚑ Auto-submit when OTP is completely filled
  • πŸ”„ Auto-focus navigation between OTP inputs
  • ❌ Error highlighting for invalid OTP/mobile number
  • πŸ“± "Change Number" option to go back and modify
  • πŸš€ Graceful fallback when SMS permissions unavailable
  • πŸ’… Smooth animations and loading states
  • 🌐 Comprehensive error handling

πŸ—οΈ Tech Stack

  • Framework: React Native 0.82.1
  • Language: TypeScript
  • Navigation: React Navigation v7 (Native Stack)
  • HTTP Client: Axios
  • SMS Auto-Read: react-native-sms-retriever
  • Build Tool: Gradle (Android)

πŸ“ Project Structure

StapuBoxApp/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ screens/
β”‚   β”‚   β”œβ”€β”€ SendOTPScreen.tsx      # Mobile number input screen
β”‚   β”‚   β”œβ”€β”€ VerifyOTPScreen.tsx    # OTP verification screen
β”‚   β”‚   └── SuccessScreen.tsx      # Success confirmation screen
β”‚   β”œβ”€β”€ navigation/
β”‚   β”‚   └── AppNavigator.tsx       # Navigation configuration
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ apiService.ts          # API integration layer
β”‚   β”‚   └── smsService.ts          # SMS auto-read service
β”‚   β”œβ”€β”€ types/
β”‚   β”‚   β”œβ”€β”€ navigation.ts          # Navigation type definitions
β”‚   β”‚   └── api.ts                 # API type definitions
β”‚   β”œβ”€β”€ constants/
β”‚   β”‚   β”œβ”€β”€ colors.ts              # Color palette
β”‚   β”‚   └── config.ts              # App configuration
β”‚   └── utils/                     # Utility functions
└── android/                       # Android native code

πŸš€ Setup Instructions

Prerequisites

  • Node.js >= 20
  • npm or yarn
  • Android Studio
  • JDK 17 (Required - not compatible with newer versions)
  • Android SDK

Installation Steps

  1. Clone the repository

    git clone https://github.com/hemantfsu/StapuBox-OTP-App.git
    cd StapuBox-OTP-App
  2. Install dependencies

    npm install
  3. Configure API Token

    Update the API token in src/constants/config.ts:

    export const API_CONFIG = {
      BASE_URL: 'https://stapubox.com/trial',
      API_TOKEN: 'your_actual_api_token_here', // Get from StapuBox
      ...
    };
  4. Install JDK 17 (if not already installed)

    # On macOS using Homebrew
    brew install --cask temurin@17

πŸƒ Running the App

Method 1: Using Emulator (Recommended for Development)

  1. Start an Android Emulator from Android Studio (AVD Manager)

  2. Start Metro Bundler (in one terminal):

    npx react-native start
  3. Run the app (in another terminal):

    export JAVA_HOME=$(/usr/libexec/java_home -v 17)
    export ANDROID_HOME=$HOME/Library/Android/sdk
    export PATH=$PATH:$ANDROID_HOME/platform-tools
    npx react-native run-android

Method 2: Using Physical Device

  1. Enable Developer Options on your Android phone

    • Go to Settings β†’ About Phone
    • Tap "Build Number" 7 times
    • Go back β†’ Developer Options β†’ Enable "USB Debugging"
  2. Connect your phone via USB and verify connection:

    $HOME/Library/Android/sdk/platform-tools/adb devices
  3. Run the app:

    export JAVA_HOME=$(/usr/libexec/java_home -v 17)
    npx react-native run-android

Method 3: Install Pre-built APK

  1. Download the APK from GitHub Releases

  2. Install on your Android device:

    adb install app-release.apk

    Or transfer the APK to your phone and install manually.

πŸ”¨ Building APK

Debug APK (for testing):

cd android
export JAVA_HOME=$(/usr/libexec/java_home -v 17)
./gradlew assembleDebug

Output: android/app/build/outputs/apk/debug/app-debug.apk

Release APK (for distribution):

cd android
export JAVA_HOME=$(/usr/libexec/java_home -v 17)
./gradlew assembleRelease

Output: android/app/build/outputs/apk/release/app-release.apk

πŸ”„ Reloading the App

  • In Emulator: Press R twice quickly
  • In Physical Device: Shake the device β†’ Select "Reload"
  • Or: Cmd + M (Mac) / Ctrl + M (Windows/Linux) β†’ Select "Reload"

πŸ“‘ API Integration

Endpoints Used

  1. Send OTP

    POST https://stapubox.com/trial/sendOtp
    Headers: X-Api-Token, Content-Type: application/json
    Body: { "mobile": "9711231143" }
    
  2. Resend OTP

    POST https://stapubox.com/trial/resendOtp?mobile=9711231143
    Headers: X-Api-Token
    
  3. Verify OTP

    POST https://stapubox.com/trial/verifyOtp?mobile=9711231143&otp=1234
    Headers: X-Api-Token
    

πŸ” SMS Auto-Read Implementation

Android SMS Retriever API

  • Automatically reads OTP from SMS without requiring READ_SMS permission
  • Graceful fallback to manual entry if auto-read fails
  • Listens for SMS containing 4-digit OTP
  • Auto-submits when OTP is detected

How it works:

  1. App requests SMS retriever to start listening
  2. When SMS arrives with OTP, it's automatically extracted
  3. OTP is filled in the input fields
  4. Verification happens automatically after a short delay

Permissions

Required permissions in AndroidManifest.xml:

<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />

πŸ§ͺ Testing

Manual Testing Checklist

  • Mobile number validation (10 digits, starts with 6-9)
  • Send OTP API integration
  • OTP input auto-focus and navigation
  • OTP auto-submit when filled
  • Resend OTP with timer
  • Error handling for invalid OTP
  • Change number functionality
  • Success screen navigation
  • SMS auto-read on Android
  • Loading states and error messages

🎯 Assignment Checklist

Base Features (Total: 100 points)

  • Screen 1 (Send OTP): +10 βœ…
  • Working API integration (send): +5 βœ…
  • Screen 2 (Verify OTP): +10 βœ…
  • Working API integration (verify): +5 βœ…
  • Auto-read SMS (Android): +20 βœ…
  • Auto-submit on OTP filled: +10 βœ…
  • Highlight validation fail: +10 βœ…
  • Implement Resend OTP: +10 βœ…
  • GitHub repo link: +10 βœ…
  • Demo video: +10 βœ…
  • Working APK: +50 βœ…

Bonus Features (Total: 50 points)

  • Pixel-perfect Figma design: +30 βœ…
  • Extra polish (loaders, error states, UX): +20 βœ…

Total Points: 150/150 ✨

πŸ› Troubleshooting

Common Issues

Issue: "Unable to load script"

  • Solution: Make sure Metro bundler is running (npx react-native start)

Issue: "JAVA_HOME is not set correctly"

  • Solution: Run export JAVA_HOME=$(/usr/libexec/java_home -v 17)

Issue: "No connected devices"

  • Solution: Start an emulator or connect a physical device with USB debugging enabled

Issue: "Gradle build failed"

  • Solution: Ensure you're using JDK 17, not a newer version

Issue: "SMS auto-read not working"

  • Solution: This feature only works on real Android devices, not emulators

πŸ“¦ Deliverables

  • βœ… GitHub repository with complete source code
  • βœ… Comprehensive README with setup instructions
  • βœ… Working Android APK
  • βœ… Architecture documentation
  • βœ… API integration implementation
  • βœ… SMS auto-read feature

πŸ“„ License

This project is created as part of StapuBox assignment.


Repository: https://github.com/hemantfsu/StapuBox-OTP-App

Developer: Hemant Baghel

Date: November 2025

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published