Skip to content

Commit

Permalink
Switch to signInWithPopup to fix cookies issue (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
GoogolGenius authored Aug 17, 2024
1 parent c64ebee commit e79991f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
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 e79991f

Please sign in to comment.