Overview
Embedded Wallets provide secure, user-friendly authentication methods that eliminate the complexity of traditional crypto wallets. Users can access their wallets through familiar authentication patterns like email one-time passwords (OTP), without ever dealing with seed phrases or browser extensions.Looking for the technical implementation? Check out our Quickstart Guide for step-by-step integration instructions.
Authentication methods
Email OTP
Email OTP is the primary authentication method for Embedded Wallets, providing a secure and familiar experience for users.How email OTP works
How email OTP works
- User enters email: The user provides their email address in your application
- OTP sent: A 6-digit one-time password is sent to their email
- User verifies: The user enters the OTP in your application
- Wallet access: Upon successful verification, the wallet is created or accessed
Security features
Security features
- Time-limited codes: OTPs expire after 10 minutes for security
- Rate limiting: Protection against brute force attempts
- Secure delivery: Emails sent through Coinbase’s trusted infrastructure
- Device binding: Wallets are cryptographically bound to the user’s device
User experience benefits
User experience benefits
- No passwords to remember: Users don’t need to create or manage passwords
- Instant onboarding: New users can create a wallet in seconds
- Familiar process: Similar to authentication flows users already know
- Cross-device support: Users can access their wallet from up to 5 devices
SMS OTP
SMS-based one-time passwords are available as an additional authentication method, providing users with more flexibility in how they access their wallets. This is currently available only for United States based phone numbers.How SMS OTP works
How SMS OTP works
- User enters phone number: The user provides their phone number in your application
- OTP sent: A 6-digit one-time password is sent to their phone number
- User verifies: The user enters the OTP in your application
- Wallet access: Upon successful verification, the wallet is created or accessed
Security features
Security features
- Time-limited codes: OTPs expire after 5 minutes for security
- Rate limiting: Protection against brute force attempts
- Secure delivery: Text messages sent through Coinbase’s trusted infrastructure
- Device binding: Wallets are cryptographically bound to the user’s device
User experience benefits
User experience benefits
- No passwords to remember: Users don’t need to create or manage passwords
- Instant onboarding: New users can create a wallet in seconds
- Familiar process: Similar to authentication flows users already know
- Cross-device support: Users can access their wallet from up to 5 devices
SMS security considerations:
- SMS authentication is inherently vulnerable to SIM swapping attacks, where attackers can take over a user’s phone number.
- You should weigh the convenience of logging in with SMS with the potential for a user’s wallet to be taken control of.
Session management
Understanding how user sessions work with Embedded Wallets is crucial for building secure applications with proper authentication flows.Session duration
User sessions are managed through a dual-token system designed to balance security and user experience:- Maximum session length: 7 days
- Access token expiry: 15 minutes
- Refresh token expiry: 7 days
How session tokens work
When a user successfully authenticates, they receive:- Access token: Short-lived (15 minutes) token used for API requests
- Refresh token: Long-lived (7 days) token used to obtain new access tokens
Session lifecycle
Initial authentication
Initial authentication
- User completes email/SMS OTP verification or other authentication method
- System issues both access and refresh tokens
- User gains immediate access to their wallet
- Session remains active for up to 7 days with automatic token refresh
Automatic token refresh
Automatic token refresh
- Access tokens are automatically refreshed using the refresh token
- Applications continue working without interruption
Session expiration
Session expiration
- After 7 days, the refresh token expires
- User must complete authentication again
Implementation considerations
- Monitor authentication state using
onAuthStateChange()
to handle session expiration - Implement graceful fallback when tokens expire
- Consider showing session timeout warnings to users approaching the 7-day limit
- Test your application’s behavior when refresh tokens expire
Implementation approaches
There are three ways to implement authentication in your application:AuthButton
component from@coinbase/cdp-react
: Pre-built UI component (fastest integration)- React hooks from
@coinbase/cdp-hooks
: For custom React UIs with state management - Direct methods from
@coinbase/cdp-core
: For vanilla JavaScript/TypeScript or non-React frameworks
Important authentication considerations:
- Always check if a user is already signed in before starting a new authentication flow. Attempting to call
verifyEmailOTP
or ‘verifySMSOTP` while a user is already authenticated will result in an error and may leave the application in an inconsistent state. - To sign out users, use the
signOut()
method from@coinbase/cdp-core
or theAuthButton
component which handles sign out automatically.
AuthButton component (simplest)
For the fastest integration,@coinbase/cdp-react
provides a pre-built AuthButton
component that handles the entire authentication flow with a single line of code.
For more CDP React components and styling options, see the React Components documentation.By default, email authentication is the only method enabled. For enabling additional methods, refer to the AppConfig documentation
The
AuthButton
component automatically:- Shows “Sign In” when the user is not authenticated
- Shows “Sign Out” when the user is authenticated
- Handles the entire Email or SMS OTP flow internally
- Manages loading and error states
- Follows your theme configuration
React hooks
For React applications,@coinbase/cdp-hooks
provides convenient hooks that handle state management and re-renders automatically.
The React hooks automatically handle loading states, error states, and re-renders when authentication state changes. They’re the recommended approach for React applications.
Direct methods
The@coinbase/cdp-core
package provides the low-level authentication primitives for maximum control over the user experience. This approach is ideal for non-React applications or when you need fine-grained control.
Always handle authentication errors gracefully. Common errors include:
- Invalid or expired OTP codes
- Rate limiting for too many attempts
- Network connectivity issues
- Invalid project configuration
Developer-delegated authentication
This feature is in development and coming soon. This will enable applications with existing authentication systems to integrate Embedded Wallets seamlessly with their current user authentication flow.Server-side validation
Some developers take additional action (fetching additional data, starting asynchronous processes) based on a user having an active session. For security reasons, it is important that you check authentication status by validating the access token Coinbase grants a user when they log in.Best practices
Security recommendations
- Domain allowlisting: Always configure your allowed domains in CDP Portal
- HTTPS only: Never use embedded wallets on non-HTTPS sites in production
- Rate limiting: Implement rate limiting on your authentication endpoints
- Session management: Use appropriate session timeouts for your use case
State management
-
Always check authentication state: Before starting any authentication flow, verify if the user is already signed in:
-
Implement sign out: Provide a clear way for users to sign out:
For React applications, use the
AuthButton
component which handles sign out automatically, or theuseSignOut
hook: -
Avoid redundant verification: Don’t call
verifyEmailOTP
orverifySmsOTP
when a user is already authenticated. This will result in an error and may leave your application in an inconsistent state.
User experience tips
- Clear messaging: Explain why users need to verify their email
- Error handling: Provide helpful error messages for common issues
- Loading states: Show progress during authentication steps
- Success feedback: Confirm when authentication is complete
Choosing the right approach
When to use the AuthButton component
When to use the AuthButton component
When to use React hooks
When to use React hooks
Use
@coinbase/cdp-hooks
when:- You need custom authentication UI
- You want to control the authentication flow step-by-step
- You need to integrate with existing form components
- You want fine-grained control over error handling
- You’re building a custom authentication experience
When to use direct methods
When to use direct methods
Use
@coinbase/cdp-core
when:- Building vanilla JavaScript/TypeScript applications
- Working with frameworks other than React (Vue, Angular, Svelte, etc.)
- You need maximum control over the authentication flow
- Building server-side applications
- Creating custom authentication wrappers for any framework
What to read next
- React hooks: Pre-built hooks for authentication and wallet management
- React components: Ready-to-use UI components including
AuthButton
- Security configuration: Configure domain allowlisting and security settings
- API reference: Complete documentation for the CDP Web SDK