All of MoonKey’s authentication methods can be whitelabeled, allowing you to build completely custom authentication flows without using the default UI components.
Available authentication methods
MoonKey provides headless authentication hooks that give you full control over your UI:Email OTP
Passwordless email authentication with one-time codes
OAuth
Social login with Google and Apple
Wallet Auth
Web3 authentication with SIWE and SIWS
Email OTP Authentication
To whitelabel MoonKey’s passwordless email flow, use theuseLoginWithEmail hook. Call sendCode to send a verification code and loginWithCode to authenticate the user.
Basic usage
With callbacks
You can pass callbacks to handle success and error states:Flow state tracking
Thestate object tracks the current status of the authentication flow:
string
The current status of the authentication flow.Possible values:
'initial'- Flow hasn’t started'sending-code'- Sending OTP to email'waiting-code-input'- Code sent, waiting for user input'verifying-code'- Verifying the entered code'complete'- Authentication successful'error'- An error occurred
Error | null
Error object if an error occurred,
null otherwise.OAuth Authentication
To whitelabel OAuth login with Google and Apple, use theuseLoginWithOAuth hook and call initOAuth with your desired provider.
Basic usage
With callbacks
OAuth state tracking
Thestate object tracks the OAuth flow:
string
The current status of the OAuth flow.Possible values:
'idle'- No OAuth flow in progress'loading'- OAuth flow in progress'done'- OAuth authentication successful'error'- An error occurred
User | null
The authenticated user object after successful OAuth login.
Error | null
Error object if an error occurred.
You must configure OAuth credentials in the MoonKey Dashboard before using OAuth authentication.
Complete example
Here’s a complete whitelabel authentication example with both email and OAuth:Styling example
Best practices
Handle loading states
Handle loading states
Always show loading indicators during authentication:
Provide clear error messages
Provide clear error messages
Display user-friendly error messages:
Use callbacks for side effects
Use callbacks for side effects
Handle navigation and UI updates in callbacks:
Track authentication state
Track authentication state
Use the flow state to show relevant UI:
Disable inputs during loading
Disable inputs during loading
Prevent users from modifying inputs during operations:
Wait for SDK to be ready
Wait for SDK to be ready
Check the
ready state before rendering auth UI:Advanced patterns
Multi-step forms
Build multi-step authentication flows:Conditional authentication
Show different auth methods based on user type:Prefilled email
Pre-populate email for invited users:TypeScript types
For TypeScript users, here are the relevant types:Troubleshooting
Code not received
Code not received
If users don’t receive the verification code:
- Check spam/junk folders
- Verify the email address is correct
- Wait a few moments before resending
- Check your email configuration in the MoonKey Dashboard
OAuth redirect issues
OAuth redirect issues
If OAuth redirects fail:
- Verify redirect URLs in the MoonKey Dashboard
- Check that OAuth credentials are configured
- Ensure your domain is whitelisted
- Test in an incognito window to rule out browser issues
State not updating
State not updating
If the state doesn’t update correctly:
- Ensure you’re using the latest SDK version
- Check that callbacks are properly defined
- Verify the SDK is initialized correctly
- Look for console errors