Skip to content

error: "No OTP session found and no auto-initiate flag" or "Grid sign-in did not create OTP session" before the Grid sign-in process has time to complete on android app #101

@lopeselio

Description

@lopeselio

OTP Screen Error After Logout and Re-login with Different Account

Description

After logging out of one account and signing in with a different Google account, the OTP verification screen appears immediately (as intended), but shows an error: "No OTP session found and no auto-initiate flag" or "Grid sign-in did not create OTP session" before the Grid sign-in process has time to complete.

Type of Issue

  • Bug
  • Feature Request
  • Documentation
  • Question

Steps to Reproduce

  1. Sign in with Google account A
  2. Complete Grid wallet setup (OTP verification)
  3. Log out from account A
  4. Sign in with Google account B (different account)
  5. Expected: OTP screen appears with preloader, then OTP input after Grid sign-in completes
  6. Actual: OTP screen appears but shows error immediately before Grid sign-in can create the OTP session

Root Cause

A race condition occurs between:

  • AuthContext setting the auto-initiate flag and redirecting to OTP screen
  • GridContext starting the Grid sign-in process (which has a 500ms delay)
  • OTP Screen checking for the OTP session before it's created

The OTP screen was checking for the session/flag too early and stopping polling prematurely, causing the error to appear before GridContext had time to:

  1. Process the auto-initiate flag (500ms delay)
  2. Call the Grid API to start sign-in
  3. Store the OTP session in secure storage

Error Messages Observed

❌ [OTP Screen] No OTP session found and no auto-initiate flag

or

❌ [OTP Screen] Grid sign-in did not create OTP session

Expected Behavior

  1. User signs in with Google → OTP screen appears immediately
  2. Preloader shows: "Setting up your wallet..." with spinner
  3. Grid sign-in starts in background (GridContext processes auto-initiate flag)
  4. OTP session is created and stored
  5. OTP input appears for user to enter code
  6. User enters OTP → Wallet loads → Navigate to chat screen

Actual Behavior

  1. User signs in with Google → OTP screen appears immediately
  2. Error message appears: "Session error. Please sign in again." or "Grid sign-in did not complete"
  3. User sees error before Grid sign-in has time to complete
  4. Grid sign-in may complete in background, but user already sees error

Technical Details

Files Involved

  • apps/client/app/(auth)/verify-otp.tsx - OTP verification screen
  • apps/client/contexts/AuthContext.tsx - Sets auto-initiate flag after Google sign-in
  • apps/client/contexts/GridContext.tsx - Handles Grid sign-in with 500ms delay

The Race Condition

// Timeline of events:
T+0ms:   User completes Google sign-in
T+0ms:   AuthContext sets GRID_AUTO_INITIATE flag
T+0ms:   Navigation redirects to OTP screen
T+0ms:   OTP screen checks for session  NOT FOUND
T+0ms:   OTP screen checks for flag  FOUND
T+0ms:   OTP screen starts polling
T+500ms: GridContext processes flag (setTimeout delay)
T+500ms: GridContext clears flag (immediately)
T+500ms: GridContext calls initiateGridSignIn()
T+1000ms: Grid API responds with OTP session
T+1000ms: GridContext stores OTP session
T+1000ms: OTP screen polling finds session 

Problem: If OTP screen checks happen between T+500ms and T+1000ms, it sees:

  • No session (not created yet)
  • No flag (cleared by GridContext)
  • isSigningInToGrid might be false (not set yet)

This causes the early stop condition to trigger incorrectly.

Proposed Solution

  1. Increase minimum polling time: Wait at least 5 seconds before considering early stop
  2. Check authentication state: If user is authenticated, keep polling even if flag is cleared
  3. Longer timeout: Increase from 15s to 20s to handle slower network conditions
  4. Better indicator checking: Check multiple indicators (flag, isSigningInToGrid, authenticated user)
  5. Delayed polling start: If no indicators found initially, wait 2 seconds then start polling if indicators appear

Environment

  • Platform: Android (emulator)
  • Device: Android Emulator
  • Flow: Google Sign-In → Grid Wallet Setup

Additional Context

This issue is related to the overall Grid wallet setup flow improvements where:

  • OTP screen should appear immediately after Google sign-in
  • Grid wallet should load in background during OTP flow
  • User should navigate to chat after OTP completion
  • Wallet should be ready when user clicks profile (no OTP again)

Related Issues/PRs

PR to fix this issue is at #100

cc: @edgarpavlovsky

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions