feat: add self-registration with email verification
Backend:
- New endpoint: POST /api/auth/register
- New endpoint: GET /api/auth/verify/{token}
- Migration: Add email_verified, verification_token, verification_expires
- Helper: send_email() for reusable SMTP
- Validation: email format, password length (min 8), name
- Auto-login after verification (returns session token)
- Rate limit: 3 registrations per hour per IP
Features:
- Verification token valid for 24h
- Existing users marked as verified (grandfather clause)
- SMTP configured via .env (SMTP_HOST, SMTP_USER, SMTP_PASS)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
888b5c3e40
commit
c1562a27f4
3 files changed
+180
-1
No files matched your search
@@ -0,0 +1,25 @@
|
||||
-- ================================================================
|
||||
-- Migration 003: Add Email Verification Fields
|
||||
-- Version: v9c
|
||||
-- Date: 2026-03-21
|
||||
-- ================================================================
|
||||
|
||||
-- Add email verification columns to profiles table
|
||||
ALTER TABLE profiles
|
||||
ADD COLUMN IF NOT EXISTS email_verified BOOLEAN DEFAULT FALSE,
|
||||
ADD COLUMN IF NOT EXISTS verification_token TEXT,
|
||||
ADD COLUMN IF NOT EXISTS verification_expires TIMESTAMP WITH TIME ZONE;
|
||||
|
||||
-- Create index for verification token lookups
|
||||
CREATE INDEX IF NOT EXISTS idx_profiles_verification_token
|
||||
ON profiles(verification_token)
|
||||
WHERE verification_token IS NOT NULL;
|
||||
|
||||
-- Mark existing users with email as verified (grandfather clause)
|
||||
UPDATE profiles
|
||||
SET email_verified = TRUE
|
||||
WHERE email IS NOT NULL AND email_verified IS NULL;
|
||||
|
||||
COMMENT ON COLUMN profiles.email_verified IS 'Whether email address has been verified';
|
||||
COMMENT ON COLUMN profiles.verification_token IS 'One-time token for email verification';
|
||||
COMMENT ON COLUMN profiles.verification_expires IS 'Verification token expiry (24h from creation)';
|
||||
Reference in new issue
Block a user