Email and SMS authentication must be enabled in your environment’s dashboard settings before they can be used in your application.
Email Authentication
Send Email OTP
Send a verification code to the user’s email address:Verify Email OTP
Verify the OTP code entered by the user:Resend Email OTP
Allow users to request a new OTP code if the previous one expired or wasn’t received:Rate Limits
Email verification is subject to the following rate limits:- 3 attempts per 10 minutes per email address
SMS Authentication
Send SMS OTP
Send a verification code to the user’s phone number using thePhoneData structure:
Verify SMS OTP
Verify the OTP code entered by the user:Resend SMS OTP
Allow users to request a new OTP code:PhoneData Structure
The SMS authentication methods use aPhoneData object that contains:
dialCode: The country dial code (e.g., “+1” for US, “+44” for UK)iso2: The two-letter country code (e.g., “US”, “GB”, “JP”)phone: The phone number without the country code
External JWT Authentication
For apps with existing authentication systems, you can authenticate users with an external JWT:Authentication State
Check Current User
Listen for Authentication Changes
Use streams to react to authentication state changes:Logout
Built-in UI
The easiest way to add authentication is using the built-in UI which handles all authentication methods:Complete Authentication Flow
Here’s a complete example combining email and SMS authentication:Configuration
Dashboard Settings
Configure email and SMS authentication in your Dynamic dashboard:-
Enable Email Authentication:
- Go to Login & User Profile
- Toggle “Email” on to enable email authentication
- No additional configuration is required
-
Enable SMS Authentication:
- Go to Login & User Profile
- Toggle “SMS” on to enable SMS authentication
- You can optionally provide your own SMS provider credentials in the phone number settings
- This is required for phone numbers outside of US and Canada
Best Practices
1. Error Handling
Always handle errors gracefully and provide clear feedback to users:2. User Experience
- Show loading states during authentication
- Provide clear error messages
- Allow users to resend OTP if needed
- Display the email/phone where OTP was sent
- Add countdown timer for resend button
3. Security
- Never store OTP codes
- Always use HTTPS connections
- Implement proper session management
- Handle token refresh automatically
Troubleshooting
OTP Not Received
- Check that the email/phone number is valid
- Look in spam folder for email OTP
- Verify that the provider is enabled in Dynamic dashboard
- Check rate limits haven’t been exceeded
Authentication Fails
- Ensure OTP code is entered correctly
- Check that the code hasn’t expired (codes typically expire after 10 minutes)
- Verify network connectivity
- Check for any error messages in logs
Session Not Persisting
- Ensure you’re listening to
tokenChangesorauthenticatedUserChangesstreams - Verify that the SDK is properly initialized
- Check that you’re not clearing app data
- Make sure the
DynamicSDK.instance.dynamicWidgetis included in your widget tree
What’s Next
Now that you have authentication set up:- Social Authentication - Add social login options
- Session Management - Manage authenticated sessions with Streams
- Wallet Creation - Learn about automatic wallet creation
- Wallet Operations - Work with user wallets