Configure your login methods in the MoonKey Dashboard before using the login modal.
Opening the login modal
TheuseMoonKey hook exposes a start method that opens the login modal:
user object will be populated with the authenticated user’s data, and the isAuthenticated state will be true.
Showing the login modal automatically
By default, the login modal will not appear automatically. If you want it to appear automatically on page load (e.g., for unauthenticated users), you can callstart() in a useEffect:
Customizing the login modal
You can customize the appearance of the login modal by configuring theappearance prop in your MoonKeyProvider:
Available customization options
string
URL to your company logo. Displayed at the top of the login modal.Example:
'https://myapp.com/logo.png'string
Custom title text displayed in the login modal header.Default:
'Sign in'Example: 'Welcome Back'string
Custom description text displayed below the title in the login modal.Default:
'Connect your wallet or sign in with email'Example: 'Sign in to access your account'boolean
Whether to hide the close button on the login modal.Default:
falseExample: true (useful for required authentication flows)Example: Complete customization
Login methods
The login modal displays authentication options based on theloginMethods configured in your MoonKeyProvider. You can enable multiple methods to give users flexibility in how they authenticate:
Email authentication
Enable email-based passwordless authentication:OAuth providers
Enable social login with Google and Apple:You must configure OAuth credentials in the MoonKey Dashboard before using OAuth login methods.
'google'- Google OAuth'apple'- Apple Sign In
Additional OAuth providers (Microsoft, Discord, GitHub, etc) are coming soon.
Wallet authentication
Enable Web3 wallet login with Sign-In with Ethereum (SIWE) or Sign-In with Solana (SIWS):Multiple login methods
You can enable multiple login methods to give users options:Handling authentication states
After the user completes authentication, you can access their information using theuseMoonKey hook:
Closing the login modal
Users can close the login modal by:- Clicking the close button (X) in the top-right corner (unless
hideCloseistrue) - Pressing the Escape key
- Clicking outside the modal (on the backdrop)
Creating embedded wallets
By default, MoonKey will not automatically create an embedded wallet when a user logs in. You can configure automatic wallet creation with theembeddedWallets.createOnLogin option:
'always'- Automatically create an embedded wallet for every user on login'none'- Don’t create wallets automatically (default). You can create them manually later usinguseCreateWallet
Email OTP configuration
When using email authentication, you can customize the OTP verification experience:Email OTP configuration options
boolean
default:false
Skip showing the success screen after email verification and immediately proceed to the application.
number
default:600
Time in seconds before the OTP expires (default: 600 = 10 minutes).
number
default:3000
Time in milliseconds to display the success message before closing the modal (default: 3000 = 3 seconds).
string
default:"Verify your email"
Title text for the email verification screen.
string
default:"Didn't receive a code?"
Title text for the resend code prompt.
number
default:30
Time in seconds before users can request a new OTP code (default: 30 seconds).
string
default:"Email verified!"
Success message shown to new users after verification.
string
default:"Welcome back!"
Success message shown to existing users after verification.
string
default:"Success!"
Generic success message shown after verification.
Prefilling user information
You can prefill the login form with user information (e.g., email address) to streamline the authentication flow:Prefill configuration
object
Prefill configuration for the login form.
Complete example
Here’s a complete example showing login modal integration with all customization options:Next steps
Email OTP Screen
Customize the email verification screen
Configure Appearance
Learn about all appearance options
Authentication Methods
Explore available authentication methods
Authentication State
Managing user authentication state