From 8f26985f6716b3b0f73e94dee8d8b2bf71e0ab6d Mon Sep 17 00:00:00 2001
From: Paul Rosenzweig <paulrosenzweig@users.noreply.github.com>
Date: Fri, 26 Jul 2019 17:51:31 -0400
Subject: [PATCH] Avoid race between logging out and refreshing page (#10376)

---
 frontend/src/metabase/auth/auth.js | 8 ++++----
 frontend/src/metabase/lib/auth.js  | 6 ++----
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/frontend/src/metabase/auth/auth.js b/frontend/src/metabase/auth/auth.js
index 3f903977d75..8ddf0cc4b63 100644
--- a/frontend/src/metabase/auth/auth.js
+++ b/frontend/src/metabase/auth/auth.js
@@ -67,7 +67,7 @@ export const loginGoogle = createThunkAction(LOGIN_GOOGLE, function(
       await dispatch(refreshCurrentUser());
       dispatch(push(redirectUrl || "/"));
     } catch (error) {
-      clearGoogleAuthCredentials();
+      await clearGoogleAuthCredentials();
       // If we see a 428 ("Precondition Required") that means we need to show the "No Metabase account exists for this Google Account" page
       if (error.status === 428) {
         dispatch(push("/auth/google_no_mb_account"));
@@ -81,12 +81,12 @@ export const loginGoogle = createThunkAction(LOGIN_GOOGLE, function(
 // logout
 export const LOGOUT = "metabase/auth/LOGOUT";
 export const logout = createThunkAction(LOGOUT, function() {
-  return function(dispatch, getState) {
+  return async function(dispatch, getState) {
     // actively delete the session and remove the cookie
-    SessionApi.delete();
+    await SessionApi.delete();
 
     // clear Google auth credentials if any are present
-    clearGoogleAuthCredentials();
+    await clearGoogleAuthCredentials();
 
     MetabaseAnalytics.trackEvent("Auth", "Logout");
 
diff --git a/frontend/src/metabase/lib/auth.js b/frontend/src/metabase/lib/auth.js
index 4a865e5b563..49c0209a9d6 100644
--- a/frontend/src/metabase/lib/auth.js
+++ b/frontend/src/metabase/lib/auth.js
@@ -1,7 +1,7 @@
 /*global gapi*/
 
 /// clear out Google Auth credentials in browser if present
-export function clearGoogleAuthCredentials() {
+export async function clearGoogleAuthCredentials() {
   const googleAuth =
     typeof gapi !== "undefined" && gapi && gapi.auth2
       ? gapi.auth2.getAuthInstance()
@@ -11,9 +11,7 @@ export function clearGoogleAuthCredentials() {
   }
 
   try {
-    googleAuth.signOut().then(function() {
-      console.log("Cleared Google Auth credentials.");
-    });
+    await googleAuth.signOut();
   } catch (error) {
     console.error("Problem clearing Google Auth credentials", error);
   }
-- 
GitLab