Skip to content

Commit

Permalink
Switch to signInWithPopup to fix cookies issue
Browse files Browse the repository at this point in the history
  • Loading branch information
GoogolGenius committed Aug 16, 2024
1 parent 21111bb commit 0b2d02e
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 0b2d02e

Please sign in to comment.