#!/bin/bash # Test OTP Email Flow # This script tests the complete OTP email verification flow echo "🔐 Testing OTP Email Verification Flow" echo "========================================" echo "" # Configuration SUPABASE_URL="https://lovable.backoffice.biz.id" # You need to get your service role key from Coolify/Docker SERVICE_KEY="YOUR_SERVICE_ROLE_KEY_HERE" echo "⚠️ IMPORTANT: Replace YOUR_SERVICE_ROLE_KEY_HERE with your actual service role key" echo " You can find it in Coolify → Supabase service → Environment variables" echo "" # Step 1: Register a test user (using curl) echo "Step 1: Creating test user..." echo "Run this in Supabase SQL Editor first:" echo "" echo "-- Clean up any existing test user" echo "DELETE FROM auth_otps WHERE email = 'test@example.com';" echo "DELETE FROM auth.users WHERE email = 'test@example.com';" echo "" # Step 2: Test the send-auth-otp edge function echo "Step 2: Testing send-auth-otp edge function..." echo "" echo "Replace USER_ID with the actual UUID from step 1, then run:" echo "" echo "curl -X POST ${SUPABASE_URL}/functions/v1/send-auth-otp \\" echo " -H \"Authorization: Bearer \${SERVICE_KEY}\" \\" echo " -H \"Content-Type: application/json\" \\" echo " -d '{" echo " \"user_id\": \"USER_UUID_HERE\"," echo " \"email\": \"test@example.com\"" echo " }'" echo "" # Step 3: Check if OTP was created echo "Step 3: Check if OTP was created in database..." echo "Run this in Supabase SQL Editor:" echo "" echo "SELECT" echo " id," echo " user_id," echo " email," echo " otp_code," echo " expires_at," echo " used_at," echo " created_at" echo "FROM auth_otps" echo "WHERE email = 'test@example.com'" echo "ORDER BY created_at DESC" echo "LIMIT 1;" echo "" # Step 4: Check notification settings echo "Step 4: Check notification settings..." echo "Run this in Supabase SQL Editor:" echo "" echo "SELECT" echo " id," echo " platform_name," echo " from_name," echo " from_email," echo " api_token," echo " mailketing_api_token" echo "FROM notification_settings" echo "LIMIT 1;" echo "" # Step 5: Check email template echo "Step 5: Check email template..." echo "Run this in Supabase SQL Editor:" echo "" echo "SELECT" echo " key," echo " name," echo " is_active," echo " email_subject," echo " LENGTH(email_body_html) as html_length" echo "FROM notification_templates" echo "WHERE key = 'auth_email_verification';" echo "" echo "========================================" echo "Common Issues:" echo "========================================" echo "" echo "1. If curl returns 404: Edge function not deployed" echo " Solution: Deploy the function from your server" echo "" echo "2. If curl returns 401: Invalid service role key" echo " Solution: Check SERVICE_KEY is correct" echo "" echo "3. If curl returns 500: Check edge function logs" echo " Solution: SSH into server and check Docker logs" echo "" echo "4. If OTP created but no email: Mailketing API issue" echo " Solution: Check api_token in notification_settings" echo ""