Authentication with MoonKey
MoonKey provides a comprehensive authentication system that supports multiple login methods, giving your users flexibility while maintaining security. Whether you’re building for web3-native users or traditional audiences, MoonKey handles the complexity of authentication so you can focus on building your product.Supported authentication methods
MoonKey offers a variety of authentication methods:Passwordless authentication
- Email OTP: One-time passcode sent to a user’s email address for passwordless login
Social login (OAuth)
Web3 authentication
- Wallet login: External wallet authentication using:
- Sign-In With Ethereum (SIWE) for Ethereum and EVM-compatible chains
- Sign-In With Solana (SIWS) for Solana
Flexible authentication flows
MoonKey allows you to configure authentication methods in two ways:- Upfront login methods: Users can authenticate directly with these methods during initial login
- Linked accounts: Users can connect additional authentication methods to their profile after initial login
The unified user object
All of MoonKey’s authentication methods create a common user object. Regardless of how a user authenticates—whether through email, OAuth, or a wallet—they’re represented by the same user structure. The user object contains:- A unique user ID
- All linked accounts (emails, wallets, OAuth providers)
- Authentication factors and verification status
- User metadata and profile information
Getting started
Using the React SDK
The easiest way to integrate MoonKey authentication is with the React SDK, which provides pre-built UI components and hooks:Using the REST API
For more control or custom integrations, use the REST API directly:Configuration and setup
Dashboard configuration
Configure your authentication methods in the MoonKey Dashboard:- Configure login methods - Enable email, OAuth, and wallet authentication
- Set up OAuth providers - Configure Google, Apple, and other social providers
- Manage redirect URLs - Set up secure redirect destinations for OAuth flows
SDK integration
React SDK
Pre-built components and hooks for React and Next.js
REST API
Direct API access for custom integrations
Node.js SDK
Server-side authentication and user management
Best practices
Security
- Use HTTPS only - Always transmit authentication credentials over secure connections
- Implement rate limiting - Protect against brute force attacks on OTP verification
- Validate sessions server-side - Never trust client-side authentication alone
User experience
- Offer multiple methods - Let users choose their preferred authentication method
- Streamline the flow - Minimize steps between login initiation and success
- Handle errors gracefully - Provide clear error messages and recovery options
Implementation
- Test thoroughly - Verify all authentication flows work correctly
- Handle edge cases - Account for expired sessions, network failures, and invalid codes
- Keep credentials secure - Store session tokens in IndexedDB