Skip to content

Commit

Permalink
Update FirebaseAnalysis.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Zain-ul-din authored Oct 25, 2024
1 parent 568d7d7 commit 6704945
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/lib/FirebaseAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { firebase, userColsRef } from './firebase';
import { useEffect } from 'react';
import { UserDocType } from './firebase_doctypes';

export function addLoggedInUser(user: User) {
export async function addLoggedInUser(user: User) {
if (!user) return;

const userDoc = doc(userColsRef, user.email as string);
Expand All @@ -23,15 +23,13 @@ export function addLoggedInUser(user: User) {
isPublic: true,
repo: 0
};

getDoc(userDoc).then((doc) => {
try {
if (doc.exists()) return;
} catch(err) {
console.log(err)
}

try {
const docSnapShot = await getDoc(userDoc);
if(!docSnapShot.exists()) setDoc(userDoc, userData, { merge: true });
} catch(_) {
setDoc(userDoc, userData, { merge: true });
});
}
}

export enum FIREBASE_ANALYTICS_EVENTS {
Expand Down

0 comments on commit 6704945

Please sign in to comment.