Firebase Anonymous Authentication utilities and helpers for React Native apps - Centralized guest user management.
- ✅ Centralized Auth Utilities: Single source of truth for anonymous/guest user checks
- ✅ Firestore Query Helpers: Skip queries for guest users automatically
- ✅ Type-Safe: Full TypeScript support
- ✅ DDD Architecture: Domain-Driven Design structure
- ✅ React Hooks: Ready-to-use React hooks for anonymous auth
npm install @umituz/react-native-firebase-anonymous@umituz/react-native-firebase>= 1.0.0@umituz/react-native-firebase-auth>= 1.0.0firebase>= 11.0.0react>= 18.2.0react-native>= 0.74.0
import { getFirebaseAuth } from '@umituz/react-native-firebase-auth';
import { checkAuthState, isGuest } from '@umituz/react-native-firebase-anonymous';
const auth = getFirebaseAuth();
const state = checkAuthState(auth);
if (state.isGuest) {
// Handle guest user
console.log('User is anonymous/guest');
}import { getFirebaseAuth } from '@umituz/react-native-firebase-auth';
import { getFirestore } from 'firebase/firestore';
import { shouldSkipFirestoreQuery } from '@umituz/react-native-firebase-anonymous';
const auth = getFirebaseAuth();
const db = getFirestore();
async function getCredits(userId: string) {
// Check if query should be skipped
const skipResult = shouldSkipFirestoreQuery(auth, {
userId,
skipForGuest: true, // Skip for guest users (default: true)
});
if (skipResult.shouldSkip) {
// Return default value for guest users
return { credits: 0 };
}
// Proceed with Firestore query
const doc = await getDoc(doc(db, 'users', userId));
return doc.data();
}import { getFirebaseAuth } from '@umituz/react-native-firebase-auth';
import { useAnonymousAuth } from '@umituz/react-native-firebase-anonymous';
function MyComponent() {
const auth = getFirebaseAuth();
const { isGuest, signInAnonymously, loading } = useAnonymousAuth(auth);
if (loading) return <Loading />;
if (!isGuest) {
return <AuthenticatedContent />;
}
return (
<View>
<Text>Guest User</Text>
<Button onPress={signInAnonymously}>Sign In Anonymously</Button>
</View>
);
}Check comprehensive authentication state.
Determine if Firestore query should be skipped based on auth state.
Options:
skipForGuest: Skip query if user is anonymous (default:true)skipIfNotAuthenticated: Skip query if user is not authenticated (default:true)verifyUserId: Verify userId matches current user (default:true)userId: User ID to verify
React hook for anonymous authentication state and operations.
This package follows Domain-Driven Design (DDD) principles:
- Domain Layer: Entities and business logic
- Infrastructure Layer: Utilities and services
- Presentation Layer: React hooks
MIT
Ümit UZ umit@umituz.com