Firebase Phone Auth Setup Guide
๐ง Required Firebase Console Setupโ
1. Enable Phone Authenticationโ
- Go to: https://console.firebase.google.com/project/toto-f9d2f/authentication/sign-in
- Click on "Phone" provider
- Enable it by toggling the switch
- Save changes
2. Add Authorized Domainsโ
- Go to: https://console.firebase.google.com/project/toto-f9d2f/authentication/settings
- Scroll to "Authorized domains"
- Add your domains:
localhost(for development)toto-f9d2f.firebaseapp.com(Firebase hosting)- Your custom domain if you have one
3. Set Up Test Phone Numbersโ
- Go to: https://console.firebase.google.com/project/toto-f9d2f/authentication/sign-in
- Click on "Phone" provider
- Expand "Phone numbers for testing"
- Add test numbers:
Phone Number: +1 650-555-3434
Verification Code: 654321
Phone Number: +54 9 11 5555-1234
Verification Code: 123456
Phone Number: +52 55 5555-1234
Verification Code: 789012
๐งช Testing Guidelinesโ
Development Testingโ
- Use test phone numbers to avoid SMS costs
- Test numbers work without actual SMS sending
- No reCAPTCHA required for test numbers
- Perfect for development and CI/CD
Production Testingโ
- Use real phone numbers for production testing
- SMS will be sent with verification codes
- reCAPTCHA required for security
- Monitor usage in Firebase Console
๐ Monitoring in Firebase Consoleโ
Authentication > Usageโ
- Monitor SMS sent count
- Check verification success rates
- Track quota usage
Authentication > Usersโ
- See verified phone numbers
- Check user creation dates
- Monitor authentication methods
Authentication > Sign-in method > Phoneโ
- View test phone numbers
- Check provider settings
- Monitor error rates
๐ Security Best Practicesโ
1. Inform Users About Securityโ
const securityInfo = phoneValidationService.getSecurityInfo();
// Display warning to users before phone auth
2. Use Multiple Auth Methodsโ
- Offer email/password alongside phone auth
- Consider social login options
- Implement 2FA when possible
3. Rate Limitingโ
- Firebase automatically limits SMS per phone number
- Monitor for abuse patterns
- Implement additional rate limiting if needed
๐จ Common Issues & Solutionsโ
Issue: "reCAPTCHA not rendered"โ
Solution:
- Check authorized domains
- Ensure reCAPTCHA container exists
- Verify Firebase config
Issue: "SMS not sent"โ
Solution:
- Check if Phone Auth is enabled
- Verify phone number format
- Check Firebase quota limits
- Use test numbers for development
Issue: "Invalid verification code"โ
Solution:
- Use correct test codes for test numbers
- Check SMS delivery for real numbers
- Verify code format (6 digits)
๐ฑ Phone Number Formatsโ
Supported Formats:โ
+54 9 11 1234-5678(Argentina)+1 (555) 123-4567(US/Canada)+52 55 1234 5678(Mexico)+34 612 345 678(Spain)
Validation Rules:โ
- Must include country code (+)
- 10-15 digits total
- No special characters except +, spaces, dashes, parentheses
๐ Testing Workflowโ
- Setup: Enable Phone Auth in Firebase Console
- Test Numbers: Add test phone numbers with codes
- Development: Use test numbers for development
- Production: Use real numbers for production testing
- Monitor: Check Firebase Console for usage and errors
๐ SMS Message Localizationโ
The SMS messages are automatically localized based on the phone number's country code:
- Argentina (+54): Spanish
- US/Canada (+1): English
- Mexico (+52): Spanish
- Spain (+34): Spanish
You can also manually set the language:
phoneValidationService.setLanguage('es'); // Spanish
phoneValidationService.setLanguage('en'); // English