Skip to content

Commit

Permalink
fix: switch to sign in with popup
Browse files Browse the repository at this point in the history
This helps prevent this issue: firebase/firebase-js-sdk#6716
  • Loading branch information
stdavis committed Feb 10, 2023
1 parent c5e2e58 commit 6e60a75
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions _src/react-app/hooks/useAuthentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,14 @@ export default function useAuthentication() {
const provider = new window.firebase.auth.OAuthProvider('oidc.utahid');
provider.addScope('app:DWRElectroFishing');

const result = await window.firebase.auth.getRedirectResult(auth);

const result = await window.firebase.auth.signInWithPopup(auth, provider);
let intervalId;
let expireTime = 0;
if (result?.user) {
const response = await result.user.getIdTokenResult();
if (checkClaims(response.claims)) {
await initServiceWorker();
sendTokenToServiceWorker(response.token);
await sendTokenToServiceWorker(response.token); // todo: switch this to an access token?
expireTime = new Date(response.expirationTime).getTime();

if (!window.Cypress) {
Expand All @@ -75,7 +74,7 @@ export default function useAuthentication() {
console.log('refreshing token');
const response = await result.user.getIdTokenResult();
expireTime = new Date(response.expirationTime).getTime();
sendTokenToServiceWorker(response.token);
await sendTokenToServiceWorker(response.token);
}
}, config.authTokenCheckInterval);
}
Expand All @@ -84,8 +83,6 @@ export default function useAuthentication() {
} else {
alert(`${result.user.email} is not authorized to use this app.`);
}
} else {
await window.firebase.auth.signInWithRedirect(auth, provider);
}

return () => {
Expand Down

0 comments on commit 6e60a75

Please sign in to comment.