From e79991fcf508699feebd605e47d4a59de83e2bd9 Mon Sep 17 00:00:00 2001 From: GoogolGenius <81032623+GoogolGenius@users.noreply.github.com> Date: Sat, 17 Aug 2024 16:30:12 -0500 Subject: [PATCH] Switch to signInWithPopup to fix cookies issue (#121) --- package-lock.json | 4 ++-- package.json | 2 +- src/index.tsx | 54 +++++++++++++++++++++++------------------------ 3 files changed, 29 insertions(+), 31 deletions(-) diff --git a/package-lock.json b/package-lock.json index b0e5fc1..89b20d4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "magnify", - "version": "2024-2025.0.2", + "version": "2024-2025.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "magnify", - "version": "2024-2025.0.2", + "version": "2024-2025.0.1", "dependencies": { "@testing-library/jest-dom": "^5.16.4", "@testing-library/react": "^13.3.0", diff --git a/package.json b/package.json index 7a75229..f6d8b9f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "magnify", - "version": "2024-2025.0.2", + "version": "2024-2025.0.1", "private": true, "dependencies": { "@testing-library/jest-dom": "^5.16.4", diff --git a/src/index.tsx b/src/index.tsx index b376cd0..d0a3444 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -141,7 +141,7 @@ const initializeCourseViewer = (): void => { const topButton = document.getElementById('to-top'); search?.addEventListener('input', filterCourses); - signInButton?.addEventListener('click', signInWithRedirect); + signInButton?.addEventListener('click', signInWithPopup); let prevScrollpos = window.scrollY; window.onscroll = () => { @@ -301,37 +301,35 @@ export const filterCourses = (): void => { }, 20); }; -firebase - .auth() - .getRedirectResult() - .then((result) => { - // The signed-in user info. - user = result.user; - - if (user) { - document.cookie = `user=${JSON.stringify(user)}`; - } +const signInWithPopup = (): void => { + const button = document.getElementById('signer'); + if (button?.textContent === 'Login') { + firebase + .auth() + .signInWithPopup(provider) + .then((result) => { + // The signed-in user info. + user = result.user; - dbRef.get().then((snapshot) => { - if (!snapshot.exists()) return; - authData = snapshot.val().users; + if (user) { + document.cookie = `user=${JSON.stringify(user)}`; + } - // Authorize the user if the user has been logged-in - if (user !== null) { - Object.keys(authData).forEach((key) => { - if (user?.email === authData[key].email) { - authLevel = authData[key].level; + dbRef.get().then((snapshot) => { + if (!snapshot.exists()) return; + authData = snapshot.val().users; + + // Authorize the user if the user has been logged-in + if (user !== null) { + Object.keys(authData).forEach((key) => { + if (user?.email === authData[key].email) { + authLevel = authData[key].level; + } + }); + filterCourses(); } }); - filterCourses(); - } - }); - }); - -const signInWithRedirect = (): void => { - const button = document.getElementById('signer'); - if (button?.textContent === 'Login') { - firebase.auth().signInWithRedirect(provider); + }); } else { firebase .auth()