Skip to content

dataflows-au/supabase-sms-hook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DataFlows SMS Integration for Supabase

Send OTP verification messages through DataFlows SMS instead of Twilio or other providers. Perfect for Australian businesses looking for competitive SMS pricing.

Features

  • Phone authentication OTP delivery via DataFlows SMS API
  • Webhook signature verification for security
  • Customizable OTP message templates
  • Support for Australian and international numbers

Prerequisites

  1. A DataFlows account
  2. A Supabase project
  3. Supabase CLI installed

Quick Setup

1. Get Your DataFlows Credentials

  1. Log in to your DataFlows dashboard
  2. Navigate to Developer > Settings
  3. Copy your API Token
  4. Note your Sender ID (alphanumeric name or virtual number)

2. Deploy the Edge Function

# Clone or copy this integration to your Supabase project
cp -r supabase/functions/dataflows-sms-hook your-project/supabase/functions/

# Navigate to your project
cd your-project

# Set the required secrets
supabase secrets set DATAFLOWS_API_KEY=your_api_token_here
supabase secrets set DATAFLOWS_SENDER_ID=YourSenderID

# Deploy the function
supabase functions deploy dataflows-sms-hook

3. Configure the Send SMS Hook

  1. Go to your Supabase Dashboard
  2. Select your project
  3. Navigate to Authentication > Hooks
  4. Find Send SMS hook and click Edit
  5. Select HTTP Request as the hook type
  6. Enter your function URL:
    https://<your-project-ref>.supabase.co/functions/v1/dataflows-sms-hook
    
  7. Click Generate Secret and copy it
  8. Save the configuration

4. Set the Hook Secret

# Set the webhook secret (from step 3.7)
supabase secrets set SEND_SMS_HOOK_SECRET="v1,whsec_your_secret_here"

# Redeploy to apply the new secret
supabase functions deploy dataflows-sms-hook

5. Enable Phone Auth

  1. In Supabase Dashboard, go to Authentication > Providers
  2. Enable Phone provider
  3. Select Hook as the SMS provider (not Twilio/MessageBird)

Configuration Options

Environment Variables

Variable Required Description
DATAFLOWS_API_KEY Yes Your DataFlows API token
DATAFLOWS_SENDER_ID Yes Sender ID (alphanumeric or phone number)
SEND_SMS_HOOK_SECRET Yes Webhook secret from Supabase dashboard
OTP_MESSAGE_TEMPLATE No Custom message template (default: Your verification code is: {otp})

Custom Message Template

Set a custom OTP message:

supabase secrets set OTP_MESSAGE_TEMPLATE="Your MyApp code is: {otp}. Valid for 10 minutes."

Local Development

1. Start Supabase Locally

supabase start

2. Set Local Environment Variables

Create a .env.local file:

DATAFLOWS_API_KEY=your_api_token
DATAFLOWS_SENDER_ID=YourSenderID

3. Serve the Function Locally

supabase functions serve dataflows-sms-hook --env-file .env.local

4. Test the Function

curl -X POST http://localhost:54321/functions/v1/dataflows-sms-hook \
  -H "Content-Type: application/json" \
  -d '{
    "user": {
      "id": "test-user-id",
      "phone": "+61412345678"
    },
    "sms": {
      "otp": "123456"
    }
  }'

Testing in Your App

import { createClient } from '@supabase/supabase-js'

const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY)

// Request OTP
const { error } = await supabase.auth.signInWithOtp({
  phone: '+61412345678'
})

// Verify OTP
const { data, error } = await supabase.auth.verifyOtp({
  phone: '+61412345678',
  token: '123456',
  type: 'sms'
})

Troubleshooting

OTP not received

  1. Check function logs: supabase functions logs dataflows-sms-hook
  2. Verify your DataFlows API key is correct
  3. Ensure the phone number format includes country code (e.g., +61412345678)
  4. Check your DataFlows SMS credit balance

Webhook signature errors

  1. Ensure SEND_SMS_HOOK_SECRET matches the secret in Supabase Dashboard
  2. The secret format should be v1,whsec_<base64-secret>

Function deployment fails

  1. Ensure you have the latest Supabase CLI: supabase update
  2. Check your Supabase project is linked: supabase link

Pricing Comparison

Provider Cost per SMS (AU)
Twilio ~$0.10 AUD
DataFlows Contact for pricing

Support

License

MIT License - Feel free to use and modify for your projects.

About

Send OTP verification messages via DataFlows SMS API for Supabase Auth

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors