Himanshu Gupta

Hi, I'm Himanshu Gupta.

Curious about how things work, why people struggle, and what we can build to help. Exploring learning, AI, and human performance.

Want to know more?

Engineering

Reversing Authentication

(Why send the first message?)

User-Initiated WhatsApp Authentication for Learnzy

Engineering Case Study • Authentication Infrastructure
Built while developing Learnzy.

Executive Summary

Google OAuth through Supabase handled login, but it did not give Learnzy a verified phone number for continuing conversations with students.

I built a user-initiated WhatsApp flow: the app prepares a verification message, the student sends it, and an inbound webhook completes login. It avoids outbound SMS verification costs while establishing a WhatsApp contact channel.

Context

At the time Learnzy was using:

flowchart TD
  A[Android App] --> B[Google OAuth]
  B --> C[Supabase Authentication]

Login worked. The gap appeared afterward.

Students sent feature requests, bug reports, and study experiences to my WhatsApp. Those conversations helped shape Learnzy, but Google login did not provide a verified number for continuing them.

The Problem

I considered phone-number authentication, but conventional SMS verification added a recurring cost.

Typical authentication looked like this:

flowchart TD
  A[User] --> B[Enter Phone Number]
  B --> C[Backend]
  C --> D[SMS Provider]
  D --> E[OTP]
  E --> F[User enters OTP]
  F --> G[Authenticated]

Problems:

  • Every login generates an SMS cost.
  • Requires third-party OTP infrastructure.
  • User manually types phone number.
  • User manually types OTP.
  • Creates another infrastructure dependency.

I wanted to avoid outbound SMS verification without asking students to type a phone number or OTP.

Design Constraints

Functional Constraints

  • Must uniquely verify every user.
  • Must keep verification safe against repeated or stale attempts.
  • Must integrate with Supabase Authentication.
  • Must work on Android.

Product Constraints

  • Authentication should remain simple.
  • Students should not type unnecessary information.
  • Must establish a communication channel after signup.

Business Constraints

Avoid recurring verification-message costs. This was a hard constraint, not an optimization for later.

Existing Solutions Considered

Option 1: Traditional SMS OTP

Advantages:

  • Standard
  • Familiar
  • Reliable

Rejected because:

  • Fixed recurring cost
  • Requires SMS provider
  • Doesn’t satisfy business constraint

Option 2: Google Authentication

Advantages:

  • Easy onboarding

Rejected because:

  • No verified mobile number
  • Poor communication channel
  • Feedback loop remains broken

Option 3: WhatsApp Business Outbound Message

Advantages:

  • Uses WhatsApp

Rejected because:

  • Still incurs outbound messaging costs
  • Doesn’t solve the core constraint

Whiteboard Thinking

The question that changed the design was: why must the server send the first message?

Known Facts

  • WhatsApp was already common among the students I was reaching.
  • A user-initiated message removes the outbound verification message from the flow.
  • WhatsApp supports deep links.
  • Messages can be pre-filled.
  • Every authentication attempt can carry a short-lived verification payload.
  • Incoming WhatsApp messages can reach the backend through webhooks.

Together, deep links, pre-filled messages, per-attempt payloads, and inbound webhooks made a user-initiated flow possible.

The Insight

I reversed the direction of the verification message.

Instead of:

flowchart TD
  A[Server] --> B[Send OTP]
  B --> C[User]

Reverse it.

flowchart TD
  A[User] --> B[Send Verification]
  B --> C[Server]

The student sends the verification message; the server checks it.

Final Architecture

flowchart TD
  A[Learnzy Android App] --> B[Prepare Verification Payload]
  B --> C[Open WhatsApp Deep Link Automatically]
  C --> D[Pre-filled Verification Message]
  D --> E[User taps Send]
  E --> F[WhatsApp Business Number]
  F --> G[Incoming Webhook]
  G --> H[Supabase Edge Function]
  H --> I[Verify Incoming Message]
  I --> J[Complete App Login]
  J --> K[User Logged Into Learnzy]

Sequence Diagram

Learnzy WhatsApp authentication flow
WhatsApp verification flow inside Learnzy.
sequenceDiagram
  participant User
  participant App as Learnzy App
  participant WA as WhatsApp
  participant Webhook
  participant Edge as Supabase Edge Function

  User->>App: Tap Login
  App->>App: Prepare Verification Payload
  App->>WA: Open WhatsApp
  User->>WA: Send Message
  WA->>Webhook: Webhook Triggered
  Webhook->>Edge: Forward Verification Message
  Edge->>Edge: Verify Incoming Message
  Edge->>App: Complete Login
  App->>User: Authenticated

Authentication Flow

Step 1

The application prepares a short-lived verification payload for the login attempt.

Step 2

The app opens WhatsApp using a deep link.

The message is pre-filled, so the student does not type a phone number or code.

Step 3

The user presses Send.

The message reaches Learnzy’s WhatsApp Business account.

Step 4

The webhook gives the backend:

  • sender phone number
  • verification payload

Step 5

The incoming message is checked against the login attempt.

If valid:

  • phone number becomes verified
  • app login is completed
  • login succeeds

Comparison

Traditional OTP Learnzy Authentication
SMS Required WhatsApp Required
Server initiates verification User initiates verification
Outbound message Inbound message
Recurring SMS cost No SMS infrastructure cost
User types phone number Number read from the incoming message
User types OTP Automatic verification
Separate support channel Authentication doubles as communication channel

Engineering Decisions

Decision Reason
Avoid SMS Remove outbound SMS verification costs
Read the number from the incoming message Avoid manual phone-number entry
Use a WhatsApp deep link Open a pre-filled message in an app the target users already use
Create a payload per login attempt Match the incoming message to the correct attempt
Verify through an inbound webhook Complete login without an outbound verification message

Trade-offs

Advantages

  • Zero SMS provider dependency.
  • Minimal user interaction.
  • Verified communication channel established automatically.
  • Simple user experience.
  • Lower infrastructure complexity.

Limitations

  • Requires WhatsApp installation.
  • Depends on WhatsApp Business API.
  • Less conventional than SMS authentication.
  • Not appropriate for products targeting users without WhatsApp.

What I Learned

I initially looked for a cheaper OTP provider. Questioning who needed to send the first message led to a different flow altogether.

The useful habit was to inspect the assumption behind the implementation before optimizing it.

Future Direction

Potential future work includes:

  • Multi-device authentication
  • More explicit device/session policies
  • Automatic device recognition
  • Enterprise WhatsApp support
  • Passkey integration
  • Multi-factor authentication support

Project Outcome

The flow was deployed in Learnzy as a production authentication mechanism. It verifies the student's number through their message and provides a channel for continuing the conversation without an SMS provider.

Project Details

Field Detail
Project Type Engineering Case Study
Category Authentication Infrastructure
Built For Learnzy
Author Himanshu Gupta
Status Production
Part of LearnzyLabs

Related Work