EVMSolana
Overview
There are three ways to implement authentication in your application, each offering different levels of customization and control: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
, theuseSignOut()
hook from@coinbase/cdp-hooks
, 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
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.What to read next
- Authentication Methods: Learn about email OTP, SMS OTP, and social login options
- React Hooks: Pre-built hooks for authentication and wallet management
- React Components: Ready-to-use UI components including AuthButton
- Session Management: Understand session lifecycle and token management
- Best Practices: Security recommendations and choosing the right approach