fix: from reading from firestore

This commit is contained in:
xavidop
2025-07-23 16:52:58 +02:00
parent 7ca5c6a572
commit f1edae23ce
3 changed files with 20 additions and 3 deletions
+3 -2
View File
@@ -2,9 +2,10 @@ rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Temporarily allow all authenticated users to test auth
// Allow all operations in emulator for development
// This will only apply when using Firebase emulators
match /{document=**} {
allow read, write: if request.auth != null;
allow read, write: if true;
}
}
}
+1 -1
View File
@@ -64,7 +64,7 @@ try {
storage = getStorage(app);
// Connect to emulators in development - do this immediately after getting auth/db instances
if (process.env.NODE_ENV === 'development' && !emulatorsConnected && typeof window !== 'undefined') {
if (process.env.NODE_ENV === 'development' && !emulatorsConnected) {
try {
connectAuthEmulator(auth, 'http://localhost:9099', { disableWarnings: true });
connectFirestoreEmulator(db, 'localhost', 8080);
+16
View File
@@ -354,6 +354,22 @@ export const getUserProfile = async (userId: string): Promise<UserProfile | null
if (userSnap.exists()) {
return userSnap.data() as UserProfile;
}
// Create a basic user profile if it doesn't exist
console.log(`User profile not found for ${userId}, creating basic profile...`);
const basicProfile: Partial<UserProfile> = {
email: '',
displayName: 'Anonymous User',
};
await createOrUpdateUserProfile(userId, basicProfile);
// Return the newly created profile
const newUserSnap = await getDoc(userRef);
if (newUserSnap.exists()) {
return newUserSnap.data() as UserProfile;
}
return null;
} catch (error) {
console.error('Error getting user profile:', error);