Node.js

Connect with the Backend

Integrating the UI with the Backend Endpoints

In the previous module we built the UI and a small UI state machine (VerifyUiState). Now we’ll connect that UI to our backend.

The main idea is that the Android app will never call Vonage directly. It will only call your backend:

  • POST /verification to start the verification flow

  • POST /check-code to validate a code (SMS code for now)

  • POST /next to force the fallback channel (SMS) immediately (so we don’t wait ~20 seconds)

Let’s start with the implementation!

Start verification (POST /verification)

When the user taps Start verification:

  1. The app sends the phone number to /verification

  2. The backend returns:

    • request_id (always)
    • check_url (optional, used later for Silent Auth)
  3. In this section, we will skip Silent Auth and immediately request fallback to SMS by calling /next

  4. UI transitions to the SMS screen (EnterSms(requestId))

Submit SMS code (POST /check-code)

When the user taps Submit code:

  1. The app sends { request_id, code } to /check-code
  2. The backend responds with { verified: true/false }
  3. UI shows success or “invalid code”

Force fallback quickly (POST /next)

Calling /next is optional from a “correctness” standpoint (Vonage can fall back automatically), but it’s very useful for UX:

If we already know we won’t complete Silent Auth (or we’re not implementing it yet), calling /next avoids waiting for the Silent Auth timeout.