SignInWithBaseButton is a ready-to-use React component that provides a seamless authentication experience using Base Account. It handles the entire sign-in flow including wallet connection, message signing, and user authentication.
Installation
Basic Usage
Props
Styling Props
Button alignment within its container (default: ‘left’)
Button variant style (default: ‘solid’)
Color scheme for the button appearance (default: ‘system’)
Button size (default: ‘medium’)
Whether the button is disabled (default: false)
Event Handlers
Callback function called when the button is clicked
Callback function called when authentication completes (success or failure)
Styling Options
Alignment
Variants
Color Schemes
Sizes
Authentication Flow Integration
Complete Authentication Example
SIWE Integration
Custom Button States
Loading State
Error State Handling
Integration with Authentication Providers
NextAuth.js Integration
Below is an example of how to configure NextAuth to use Base Account as a credentials provider, so you can use Base Account in your Next.js application.NextAuth.js IntegrationNext.js is a popular React framework, and NextAuth.js is an authentication library for Next.js. It offers session management and providers.
pages/api/auth/[...nextauth].js
page.tsx
TypeScript Support
Best Practices
- Handle Loading States: Disable the button during authentication to prevent multiple attempts
- Error Handling: Provide clear error messages for different failure scenarios
- Security: Always verify signatures on your backend before trusting authentication
- User Experience: Show clear feedback during the authentication process
- Accessibility: The button includes proper ARIA labels and keyboard navigation
- Testing: Test with different wallet states (connected, disconnected, etc.)