Skip to content

Commit

Permalink
fix: if there's an issue with auth token, log out the user and refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
stdavis committed Mar 8, 2023
1 parent c67d36a commit 1a3c76e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions _src/ServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// inspired by: https://firebase.google.com/docs/auth/web/service-worker-sessions
import { initializeApp } from 'firebase/app';
import { getAuth, onAuthStateChanged, getIdToken } from 'firebase/auth';
import { getAuth, onAuthStateChanged, getIdToken, signOut } from 'firebase/auth';

initializeApp(process.env.REACT_APP_FIREBASE_CONFIG);

Expand All @@ -29,7 +29,7 @@ const getIdTokenPromise = () => {
});
}

return getIdToken(auth.currentUser);
return getIdToken(auth.currentUser).catch(() => signOut().then(() => window.location.replace(window.location.href)));
};

self.addEventListener('install', (event) => {
Expand Down

0 comments on commit 1a3c76e

Please sign in to comment.