This document explains the Twitter integration features in the AztecMint application.
The app currently includes a simplified Twitter integration that allows users to:
- Enter their Twitter username - Users can manually enter their Twitter handle
- Display profile information - Shows username, name, bio, and profile image
- Mock profile generation - Creates demo profile data for testing
- Located in
src/components/TwitterConnect.tsx - Allows users to enter their Twitter username
- Generates mock profile data for demonstration
- Uses DiceBear API for avatar generation
- Located in
src/components/TwitterProfile.tsx - Displays connected user's profile information
- Shows username, name, bio, and profile image
- Includes disconnect functionality
- Twitter section appears between wallet connection and NFT minting
- Profile information is displayed when connected
- Clean disconnect functionality
For production use with real Twitter API integration, you'll need to:
- Go to Twitter Developer Portal
- Create a new app
- Enable OAuth 2.0
- Set up callback URLs
Add these to your .env.local:
TWITTER_CLIENT_ID=your_twitter_client_id
TWITTER_CLIENT_SECRET=your_twitter_client_secret
NEXTAUTH_URL=http://localhost:3000The following API routes are already set up for OAuth 2.0:
src/app/api/twitter/auth/route.ts- Initiates OAuth flowsrc/app/api/twitter/callback/route.ts- Handles OAuth callback
The OAuth implementation requests these scopes:
tweet.read- Read user's tweetsusers.read- Read user profile information
- Click "Connect Your Twitter" section
- Enter your Twitter username
- View your profile information
- Disconnect when done
- The Twitter integration is modular and can be easily extended
- Mock data generation can be replaced with real API calls
- Profile data is stored in component state (consider persistence for production)
To replace the mock implementation:
- Update TwitterConnect component:
// Replace mock data generation with real API call
const response = await fetch('/api/twitter/auth');
const { authUrl } = await response.json();
window.location.href = authUrl;- Handle OAuth callback:
// In the main page component
useEffect(() => {
const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get('code');
const state = urlParams.get('state');
if (code && state) {
// Exchange code for user data
fetch('/api/twitter/callback?code=' + code + '&state=' + state)
.then(res => res.json())
.then(data => setTwitterUser(data.user));
}
}, []);- Tweet sharing when minting NFTs
- Twitter profile verification badges
- Social features like following other users
- Integration with NFT metadata
- OAuth State Verification - Always verify the state parameter
- HTTPS Required - Twitter OAuth requires HTTPS in production
- Token Storage - Store tokens securely (consider server-side sessions)
- Rate Limiting - Implement proper rate limiting for API calls
- CORS Errors - Ensure callback URLs are properly configured
- Invalid State - Check state parameter handling
- Token Expiration - Implement token refresh logic
- API Limits - Monitor Twitter API rate limits
- Development: Uses mock data for easy testing
- Production: Requires real Twitter API credentials and OAuth flow
twitter-api-v2- Twitter API client library- Next.js API routes for OAuth handling
- React state management for user data
For issues with Twitter integration:
- Check Twitter Developer Portal for API status
- Verify environment variables are set correctly
- Ensure callback URLs match your deployment
- Review OAuth flow implementation