Supabase OTP
This guide explains how to configure Supabase to send OTP tokens instead of magic links for email authentication.
π¨ Issue: Receiving Magic Links Instead of OTP Codes
When you request an email OTP, Supabase sends a magic link instead of a 6-digit OTP code. This happens because the default configuration prioritizes magic links over OTP codes.
π§ Solution: Configure Supabase Project Settings
Step 1: Access Supabase Dashboard
Go to https://supabase.com/dashboard
Select your project.
Navigate to Authentication β Settings
Step 2: Configure Email Auth Settings
In the Auth Settings section:
Find "Email OTP" Settings:
Look for "Email OTP" configuration
Enable "Email OTP" if it's disabled
Disable Magic Links (if needed):
Look for "Magic Link" settings
Consider disabling magic links to force OTP usage
Email Template Settings:
Go to Authentication β Email Templates
Select "Magic Link" template
Change the template type or configure it for OTP
Step 3: Alternative Approach - Use Explicit OTP Configuration
π§ Email Template Configuration
Configure Email OTP Template
Go to Authentication β Email Templates
Select "Magic Link" or find "OTP" template
Ensure the template contains
{{ .Token }}instead of{{ .ConfirmationURL }}
Example OTP email template:
π Troubleshooting
Check Current Configuration
Run this test to see what type of email you're receiving:
If Still Receiving Magic Links
Check Email Templates: Verify the template uses
{{ .Token }}not{{ .ConfirmationURL }}Project Settings: Ensure OTP is enabled in Auth settings
Cache: Clear browser cache and try again
Different Email: Try with a different email address
Alternative Solution: Use Phone OTP
If email OTP continues to send magic links, use phone OTP instead:
π§ͺ Testing After Configuration
Test Email OTP:
π± Enable SMS OTP (Optional)
If you want phone OTP:
Go to Authentication β Settings
Find "Phone Auth" section
Configure your SMS provider (Twilio, MessageBird, etc.)
Enable phone authentication
π§ Code-Level Fix (If Dashboard Doesn't Work)
If the dashboard configuration doesn't work, we can try a different approach in the code:
π Need Help?
If you're still receiving magic links after following these steps:
Check your Supabase project's Auth settings carefully
Try creating a new test project to verify OTP behavior
Contact Supabase support if the issue persists
Consider using phone OTP as an alternative
β
Expected Behavior After Fix
After proper configuration:
Email OTP: You'll receive a 6-digit code like
123456Response: API returns success message about OTP being sent
Verification: Use the 6-digit code to verify and get JWT tokens
The key is ensuring your Supabase project is configured to prioritize OTP codes over magic links in the authentication flow.
Last updated