Here's how to use the new native Twitter authentication in your TribeFind app:
# Add to your .env file
EXPO_PUBLIC_TWITTER_CLIENT_ID=your_twitter_client_id_here// In your AuthScreen or any component
import { useAuth } from '../services/AuthService'
export default function AuthScreen() {
const { signInWithTwitter } = useAuth()
const [loading, setLoading] = useState(false)
const handleTwitterSignIn = async () => {
setLoading(true)
try {
const result = await signInWithTwitter()
if (result.error) {
Alert.alert('Twitter Sign In Error', result.error)
} else {
// Success! User is now signed in
console.log('✅ Twitter sign-in successful!')
}
} catch (error) {
Alert.alert('Error', 'An unexpected error occurred')
} finally {
setLoading(false)
}
}
return (
<TouchableOpacity
style={styles.twitterButton}
onPress={handleTwitterSignIn}
disabled={loading}
>
<Text style={styles.twitterButtonText}>
{loading ? 'Signing in...' : 'Continue with Twitter'}
</Text>
</TouchableOpacity>
)
}// Direct usage of TwitterSignInService
import { TwitterSignInService } from '../services/TwitterSignInService'
// Configure the service
TwitterSignInService.configure('your_twitter_client_id')
// Sign in
const result = await TwitterSignInService.signIn()
if (result.success && result.user) {
console.log('Twitter user:', result.user)
// Handle successful authentication
} else {
console.error('Twitter sign-in failed:', result.error)
}- User taps "Continue with Twitter"
- PKCE challenge generated for security
- In-app browser opens with Twitter OAuth page
- User authorizes your app on Twitter
- App receives authorization code via deep link
- Code exchanged for access token using PKCE
- User data fetched from Twitter API
- User created/updated in Supabase database
- User signed in to your app
interface TwitterUser {
id: string // Twitter user ID
name: string // Display name
username: string // @username
email?: string // Email (if provided)
profile_image_url?: string // Avatar URL
verified?: boolean // Verified account
public_metrics?: {
followers_count: number
following_count: number
tweet_count: number
}
}The native Twitter authentication automatically:
- ✅ Creates Supabase auth user with Twitter data
- ✅ Creates user profile in your
userstable - ✅ Stores Twitter data in
social_accountsJSONB field - ✅ Generates unique username with
tw_prefix - ✅ Handles existing users by updating their Twitter connection
Common errors and solutions:
const result = await signInWithTwitter()
switch (result.error) {
case 'Twitter Client ID is not configured':
// Add EXPO_PUBLIC_TWITTER_CLIENT_ID to .env
break
case 'Invalid redirect URI':
// Check Twitter app callback URL is tribefind://auth/twitter
break
case 'User cancelled Twitter authentication':
// User closed the browser - normal behavior
break
case 'Token exchange failed':
// Check Twitter app OAuth 2.0 settings
break
}- Twitter app configured as Native App type
- Callback URL set to
tribefind://auth/twitter - Client ID added to
.envfile - Test on physical device (not simulator)
- Check deep linking works with
tribefind://scheme
| Native Authentication | Web OAuth (Old) |
|---|---|
| ✅ In-app browser | ❌ System browser |
| ✅ PKCE security | |
| ✅ No Supabase config | ❌ Provider setup required |
| ✅ Direct user management | ❌ Complex session handling |
| ✅ Better UX | ❌ App switching |
Your app now has professional native Twitter authentication! 🚀