Skip to content

Latest commit

 

History

History
139 lines (106 loc) · 5.02 KB

File metadata and controls

139 lines (106 loc) · 5.02 KB

SMS Issue Analysis & Solution

Problem Summary

SMS messages are only working for one specific phone number (+16508042454), while other numbers (+16693223469) don't receive messages, even though the API reports "success".

Root Cause Analysis

1. Configuration Status

  • Environment Variables: All Twilio environment variables show as "NOT_SET" in our diagnostic
  • API Behavior: SMS API calls return "success" for both numbers
  • Actual Delivery: Only one number receives messages

2. Most Likely Cause: Twilio Trial Account Restrictions

This behavior is classic Twilio trial account limitation:

Twilio Trial Account Restrictions:

  • Verified Numbers Only: Trial accounts can only send SMS to phone numbers that have been explicitly verified
  • API Success: Twilio API will return "success" even for unverified numbers
  • Silent Failure: Messages to unverified numbers are silently dropped
  • No Error Indication: The application has no way to know the message wasn't delivered

3. Configuration Analysis

The fact that SMS works at all (despite environment variables being NOT_SET) indicates:

  • Supabase Project-Level Configuration: SMS is configured directly in Supabase dashboard, not via environment variables
  • Working Integration: The Twilio integration is functional
  • Delivery Restriction: The issue is at the Twilio account level, not code level

Solutions

Immediate Solutions

Option 1: Verify Additional Phone Numbers (Trial Account)

  1. Log into Twilio Console
  2. Go to Phone NumbersManageVerified Caller IDs
  3. Click Add a new number
  4. Add +16693223469 and any other test numbers
  5. Complete the verification process for each number

Option 2: Upgrade Twilio Account (Recommended)

  1. Log into Twilio Console
  2. Go to AccountBilling
  3. Add payment method and upgrade from trial to paid account
  4. This removes the verified number restriction
  5. SMS will work for any valid phone number

Long-term Solutions

Fix Environment Variable Configuration

Even though SMS works, the environment variables should be properly configured:

  1. Check Current Supabase Configuration:

    • Log into Supabase Dashboard
    • Go to AuthenticationSettingsSMS
    • Note the current Twilio configuration
  2. Update .env File (use the same values from Supabase dashboard):

    # Add these to your .env file
    PROJECT_REF=your-supabase-project-ref
    SUPABASE_ACCESS_TOKEN=your-access-token
    TWILIO_ACCOUNT_SID=your-twilio-account-sid
    TWILIO_AUTH_TOKEN=your-twilio-auth-token
    TWILIO_PHONE_NUMBER=your-twilio-phone-number
  3. Run Configuration Script:

    ./scripts/supabase-twilio.sh

Verification Steps

Test Both Numbers Again

After implementing solutions, test both numbers:

# Test first number
curl -X POST http://localhost:8080/api/auth/send-sms \
  -H "Content-Type: application/json" \
  -d '{"phoneNumber":"+16508042454"}'

# Test second number  
curl -X POST http://localhost:8080/api/auth/send-sms \
  -H "Content-Type: application/json" \
  -d '{"phoneNumber":"+16693223469"}'

Check Twilio Logs

  1. Go to Twilio Console
  2. Navigate to MonitorLogsMessaging
  3. Look for recent SMS attempts
  4. Check delivery status for both numbers

Expected Outcomes

After Verifying Numbers (Trial Account)

  • Both numbers should receive SMS messages
  • API will continue to return "success"
  • Twilio logs will show "delivered" status

After Upgrading Account (Recommended)

  • Any valid phone number will receive SMS messages
  • No need to pre-verify numbers
  • Full SMS functionality for production use

Prevention

Monitoring & Alerting

Consider implementing:

  1. Twilio Webhook Integration: Get delivery status callbacks
  2. SMS Delivery Monitoring: Track actual delivery vs. API success
  3. Account Limit Monitoring: Alert when approaching trial limits

Documentation

Update your deployment documentation to include:

  1. Twilio account requirements
  2. Environment variable setup
  3. SMS testing procedures

Technical Details

Why Environment Variables Show as NOT_SET

The diagnostic tool checks process.env variables, but Supabase can be configured via:

  1. Dashboard Configuration: Direct setup in Supabase UI
  2. Management API: Using scripts like supabase-twilio.sh
  3. Environment Variables: Runtime configuration (what we're checking)

Your setup uses dashboard/API configuration, which is why environment variables appear unset but SMS still works.

SMS Flow

  1. Applicationsupabase.auth.signInWithOtp()
  2. Supabase → Uses configured Twilio credentials
  3. Twilio → Sends SMS (or silently drops for unverified numbers)
  4. Response → Always returns "success" to Supabase
  5. Supabase → Returns "success" to application

The issue occurs at step 3, where Twilio silently drops messages to unverified numbers in trial accounts.