From 80f3c4e28c7c4648a643cc2022b1f359b90e74cb Mon Sep 17 00:00:00 2001 From: Teal Larson Date: Thu, 12 Jan 2023 16:51:31 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=9F=20=F0=9F=8E=89=20Verify=20auth=20s?= =?UTF-8?q?tatus=20on=20tab=20focus=20(#21175)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cloud/services/auth/AuthService.tsx | 19 ++++++++++++++++++- .../src/packages/cloud/views/auth/Auth.tsx | 8 +++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/airbyte-webapp/src/packages/cloud/services/auth/AuthService.tsx b/airbyte-webapp/src/packages/cloud/services/auth/AuthService.tsx index d62714cd5b9d..248154205c21 100644 --- a/airbyte-webapp/src/packages/cloud/services/auth/AuthService.tsx +++ b/airbyte-webapp/src/packages/cloud/services/auth/AuthService.tsx @@ -1,5 +1,5 @@ import { User as FirebaseUser } from "firebase/auth"; -import React, { useCallback, useContext, useMemo, useRef } from "react"; +import React, { useCallback, useContext, useEffect, useMemo, useRef } from "react"; import { useQueryClient } from "react-query"; import { useEffectOnce } from "react-use"; import { Observable, Subject } from "rxjs"; @@ -160,6 +160,23 @@ export const AuthenticationProvider: React.FC> }); }); + useEffect(() => { + const onFocus = async () => { + return auth.onAuthStateChanged(async (currentUser) => { + if (!currentUser) { + loggedOut(); + } else { + await onAfterAuth(currentUser); + } + }); + }; + + window.addEventListener("focus", onFocus); + return () => { + window.removeEventListener("focus", onFocus); + }; + }, [auth, loggedOut, onAfterAuth]); + const queryClient = useQueryClient(); const ctx: AuthContextApi = useMemo( diff --git a/airbyte-webapp/src/packages/cloud/views/auth/Auth.tsx b/airbyte-webapp/src/packages/cloud/views/auth/Auth.tsx index d614f6dfd520..f4852fd0f305 100644 --- a/airbyte-webapp/src/packages/cloud/views/auth/Auth.tsx +++ b/airbyte-webapp/src/packages/cloud/views/auth/Auth.tsx @@ -54,7 +54,13 @@ export const Auth: React.FC = () => { } /> } + element={ + + } />