From 6c38cb7c7c5052e29962747e180e6c09ed2d1fab Mon Sep 17 00:00:00 2001 From: tttm <80350771+33tm@users.noreply.github.com> Date: Wed, 27 Sep 2023 17:57:21 -0700 Subject: [PATCH 1/2] fix eternal sgyauth modal --- .../components/firebase/SgyInitResults.tsx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/client/src/components/firebase/SgyInitResults.tsx b/client/src/components/firebase/SgyInitResults.tsx index 74580b2e..64313dbe 100644 --- a/client/src/components/firebase/SgyInitResults.tsx +++ b/client/src/components/firebase/SgyInitResults.tsx @@ -9,6 +9,7 @@ import Loading from '../layout/Loading'; // Auth import { useAuth, useFirestore, useFunctions, useUser } from 'reactfire'; +import { onAuthStateChanged } from 'firebase/auth'; import { httpsCallable } from 'firebase/functions'; import { updateUserData } from '../../util/firestore'; @@ -31,14 +32,16 @@ export default function SgyInitResults() { // Set the results to the value returned by initialization to be displayed useEffect(() => { - if (auth.currentUser && sgyModal) { - // console.log('hey!'); - const init = httpsCallable(functions, "sgyfetch-init"); - init().then(r => { - // console.log(r); - setResults(r); - }); - } + onAuthStateChanged(auth, (user) => { + if (user && sgyModal) { + // console.log('hey!'); + const init = httpsCallable(functions, "sgyfetch-init"); + init().then(r => { + // console.log(r); + setResults(r); + }); + } + }) // return (() => {console.log('I am unmounted!!!!!')}); }, []) From 146975fc2752c59cc61a5b065e242d22e5f0ca65 Mon Sep 17 00:00:00 2001 From: tttm <80350771+33tm@users.noreply.github.com> Date: Wed, 27 Sep 2023 20:06:58 -0700 Subject: [PATCH 2/2] Update SgyInitResults.tsx --- .../components/firebase/SgyInitResults.tsx | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/client/src/components/firebase/SgyInitResults.tsx b/client/src/components/firebase/SgyInitResults.tsx index 64313dbe..e130e7cb 100644 --- a/client/src/components/firebase/SgyInitResults.tsx +++ b/client/src/components/firebase/SgyInitResults.tsx @@ -9,7 +9,6 @@ import Loading from '../layout/Loading'; // Auth import { useAuth, useFirestore, useFunctions, useUser } from 'reactfire'; -import { onAuthStateChanged } from 'firebase/auth'; import { httpsCallable } from 'firebase/functions'; import { updateUserData } from '../../util/firestore'; @@ -32,18 +31,17 @@ export default function SgyInitResults() { // Set the results to the value returned by initialization to be displayed useEffect(() => { - onAuthStateChanged(auth, (user) => { - if (user && sgyModal) { - // console.log('hey!'); - const init = httpsCallable(functions, "sgyfetch-init"); - init().then(r => { - // console.log(r); - setResults(r); - }); - } - }) + if (!auth.currentUser) return; + if (auth.currentUser && sgyModal) { + // console.log('hey!'); + const init = httpsCallable(functions, "sgyfetch-init"); + init().then(r => { + // console.log(r); + setResults(r); + }); + } // return (() => {console.log('I am unmounted!!!!!')}); - }, []) + }, [auth.currentUser]) const closeDialog = () => { setSgyModal(false);