Add master template wrapper to OTP emails

- Add EmailTemplateRenderer class to send-auth-otp edge function
- Wrap OTP email content in master template with brutalist design
- Email now includes proper header, footer, and styling
- No changes needed to checkout flow (uses auth page for registration)

Benefits:
- Professional branded emails with ACCESS HUB header
- Consistent brutalist design across all emails
- Responsive layout
- Better email client compatibility
This commit is contained in:
dwindown
2026-01-02 15:19:41 +07:00
parent 967829b612
commit bd3841b716
2 changed files with 420 additions and 3 deletions

156
DEPLOY-OTP-FIX.md Normal file
View File

@@ -0,0 +1,156 @@
# Deploy OTP Email Fix
## Problem
The `send-auth-otp` edge function was trying to insert into `notification_logs` table which doesn't exist, causing the function to crash AFTER sending the email. This meant:
- ✅ Email was sent by Mailketing API
- ❌ Function crashed before returning success
- ❌ Frontend might have shown error
## Solution
Removed all references to `notification_logs` table from the edge function.
## Deployment Steps
### 1. SSH into your server
```bash
ssh root@lovable.backoffice.biz.id
```
### 2. Navigate to the project directory
```bash
cd /path/to/your/project
```
### 3. Pull the latest changes
```bash
git pull origin main
```
### 4. Deploy the edge function
```bash
# Option A: If using Supabase CLI
supabase functions deploy send-auth-otp
# Option B: If manually copying files
cp supabase/functions/send-auth-otp/index.ts /path/to/supabase/functions/send-auth-otp/index.ts
# Then restart the edge function container
docker-compose restart edge-functions
# or
docker restart $(docker ps -q --filter 'name=supabase_edge_runtime')
```
### 5. Verify deployment
```bash
# Check if function is loaded
supabase functions list
# Should show:
# send-auth-otp ...
# verify-auth-otp ...
# send-email-v2 ...
```
### 6. Test the fix
```bash
# Test with curl
curl -X POST https://lovable.backoffice.biz.id/functions/v1/send-auth-otp \
-H "Authorization: Bearer YOUR_SERVICE_ROLE_KEY" \
-H "Content-Type: application/json" \
-d '{"user_id":"TEST_USER_ID","email":"test@example.com"}'
# Expected response:
# {"success":true,"message":"OTP sent successfully"}
```
### 7. Test full registration flow
1. Open browser to https://with.dwindi.com/auth
2. Register with new email
3. Check email inbox
4. Should receive OTP code
## What Changed
### File: `supabase/functions/send-auth-otp/index.ts`
**Before:**
```typescript
// Log notification
await supabase
.from('notification_logs')
.insert({
user_id,
email: email,
notification_type: 'auth_email_verification',
status: 'sent',
provider: 'mailketing',
error_message: null,
});
```
**After:**
```typescript
// Note: notification_logs table doesn't exist, skipping logging
```
## Troubleshooting
### If email still not received:
1. **Check edge function logs:**
```bash
docker logs $(docker ps -q --filter 'name=supabase_edge_runtime') | tail -50
```
2. **Check if OTP was created:**
```sql
SELECT * FROM auth_otps ORDER BY created_at DESC LIMIT 1;
```
3. **Check notification settings:**
```sql
SELECT platform_name, from_name, from_email, api_token
FROM notification_settings
LIMIT 1;
```
4. **Verify email template:**
```sql
SELECT key, name, is_active, LENGTH(email_body_html) as html_length
FROM notification_templates
WHERE key = 'auth_email_verification';
```
5. **Test email sending directly:**
```bash
curl -X POST https://lovable.backoffice.biz.id/functions/v1/send-email-v2 \
-H "Authorization: Bearer YOUR_SERVICE_ROLE_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "your@email.com",
"api_token": "YOUR_MAILKETING_TOKEN",
"from_name": "Test",
"from_email": "test@with.dwindi.com",
"subject": "Test Email",
"html_body": "<h1>Test</h1>"
}'
```
## Success Criteria
✅ Edge function returns `{"success":true}`
✅ No crashes in edge function logs
✅ OTP created in database
✅ Email received with OTP code
✅ OTP verification works
✅ User can login after verification
## Next Steps
After successful deployment:
1. Test registration with multiple email addresses
2. Test OTP verification flow
3. Test login after verification
4. Test "resend OTP" functionality
5. Test expired OTP (wait 15 minutes)
6. Test wrong OTP code