Files
meet-hub/supabase/migrations/20250102000002_auth_email_template.sql
dwindown 0d29c953c1 Implement OTP-based email verification system
Add custom email verification using 6-digit OTP codes via Mailketing API:

Database:
- Create auth_otps table with 15-minute expiry
- Add indexes and RLS policies for security
- Add cleanup function for expired tokens
- Insert default auth_email_verification template

Edge Functions:
- send-auth-otp: Generate OTP, store in DB, send via Mailketing
- verify-auth-otp: Validate OTP, confirm email in Supabase Auth

Frontend:
- Add OTP input state to auth page
- Implement send/verify OTP in useAuth hook
- Add resend countdown timer (60 seconds)
- Update auth flow: signup → OTP verification → login

Features:
- Instant email delivery (no queue/cron)
- 6-digit OTP with 15-minute expiry
- Resend OTP with cooldown
- Admin-configurable email templates
- Indonesian UI text

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-02 13:27:46 +07:00

163 lines
4.5 KiB
SQL

-- ============================================================================
-- Auth Email Verification Template
-- ============================================================================
-- Insert default auth email verification template
INSERT INTO notification_templates (
template_key,
template_name,
description,
subject,
html_content,
is_active,
created_at,
updated_at
) VALUES (
'auth_email_verification',
'Verifikasi Email - OTP',
'Template untuk mengirim kode OTP verifikasi email saat pendaftaran',
'Kode Verifikasi Email Anda - {platform_name}',
'---
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Verifikasi Email</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
background-color: #f5f5f5;
margin: 0;
padding: 20px;
line-height: 1.6;
}
.container {
max-width: 600px;
margin: 0 auto;
background: white;
border: 3px solid #000;
box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.2);
}
.header {
background: #000;
color: #fff;
padding: 30px;
text-align: center;
}
.header h1 {
margin: 0;
font-size: 24px;
font-weight: 700;
}
.content {
padding: 30px;
}
.greeting {
font-size: 18px;
margin-bottom: 20px;
}
.message {
margin-bottom: 30px;
color: #333;
}
.otp-container {
background: #f9f9f9;
border: 2px dashed #000;
padding: 30px;
text-align: center;
margin: 30px 0;
}
.otp-code {
font-size: 36px;
font-weight: 700;
letter-spacing: 8px;
color: #000;
font-family: "Courier New", monospace;
margin: 20px 0;
}
.expiry {
font-size: 14px;
color: #666;
margin-top: 10px;
}
.instructions {
background: #fffbeb;
border-left: 4px solid #f59e0b;
padding: 15px;
margin: 20px 0;
font-size: 14px;
}
.footer {
background: #f9f9f9;
padding: 20px;
text-align: center;
font-size: 12px;
color: #666;
border-top: 2px solid #000;
}
.button {
display: inline-block;
background: #000;
color: #fff;
padding: 12px 24px;
text-decoration: none;
font-weight: 600;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🔐 Verifikasi Email</h1>
</div>
<div class="content">
<p class="greeting">Halo {nama},</p>
<p class="message">
Terima kasih telah mendaftar di <strong>{platform_name}</strong>!
Gunakan kode OTP berikut untuk memverifikasi alamat email Anda:
</p>
<div class="otp-container">
<div class="otp-code">{otp_code}</div>
<div class="expiry">⏰ Berlaku selama {expiry_minutes} menit</div>
</div>
<div class="instructions">
<strong>Cara menggunakan:</strong><br>
1. Salin kode 6 digit di atas<br>
2. Kembali ke halaman pendaftaran<br>
3. Masukkan kode tersebut pada form verifikasi
</div>
<p class="message" style="margin-top: 30px;">
Jika Anda tidak merasa mendaftar di {platform_name},
abaikan email ini dengan aman.
</p>
</div>
<div class="footer">
<p>Email ini dikirim ke {email}</p>
<p>© {year} {platform_name}. Semua hak dilindungi.</p>
</div>
</div>
</body>
</html>
---',
true,
NOW(),
NOW()
) ON CONFLICT (template_key) DO NOTHING;
-- Add comment
COMMENT ON TABLE notification_templates IS 'Contains email templates for various notifications including auth emails';
-- Return success message
DO $$
BEGIN
RAISE NOTICE 'Auth email verification template inserted successfully';
END $$;