From cc006f9d40c5c814db36efbd63c627ecad056b70 Mon Sep 17 00:00:00 2001 From: tealjulia Date: Mon, 9 Jan 2023 15:32:53 -0500 Subject: [PATCH 1/3] check of whether a user is logged out on tab focus --- .../cloud/services/auth/AuthService.tsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/airbyte-webapp/src/packages/cloud/services/auth/AuthService.tsx b/airbyte-webapp/src/packages/cloud/services/auth/AuthService.tsx index d62714cd5b9d..1e04c0d31cc3 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,21 @@ export const AuthenticationProvider: React.FC> }); }); + useEffect(() => { + const onFocus = () => { + return auth.onAuthStateChanged((currentUser) => { + if (!currentUser) { + loggedOut(); + } + }); + }; + + window.addEventListener("focus", onFocus); + return () => { + window.removeEventListener("focus", onFocus); + }; + }, [auth, loggedOut]); + const queryClient = useQueryClient(); const ctx: AuthContextApi = useMemo( From 6cc346f2196dfaa36d3751cd14f5de2b8719d48e Mon Sep 17 00:00:00 2001 From: tealjulia Date: Tue, 10 Jan 2023 08:44:11 -0500 Subject: [PATCH 2/3] check for logged in status in onFocus, adjust logic for redirect URL when logged out --- .../packages/cloud/services/auth/AuthService.tsx | 8 +++++--- .../src/packages/cloud/views/auth/Auth.tsx | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/airbyte-webapp/src/packages/cloud/services/auth/AuthService.tsx b/airbyte-webapp/src/packages/cloud/services/auth/AuthService.tsx index 1e04c0d31cc3..248154205c21 100644 --- a/airbyte-webapp/src/packages/cloud/services/auth/AuthService.tsx +++ b/airbyte-webapp/src/packages/cloud/services/auth/AuthService.tsx @@ -161,10 +161,12 @@ export const AuthenticationProvider: React.FC> }); useEffect(() => { - const onFocus = () => { - return auth.onAuthStateChanged((currentUser) => { + const onFocus = async () => { + return auth.onAuthStateChanged(async (currentUser) => { if (!currentUser) { loggedOut(); + } else { + await onAfterAuth(currentUser); } }); }; @@ -173,7 +175,7 @@ export const AuthenticationProvider: React.FC> return () => { window.removeEventListener("focus", onFocus); }; - }, [auth, loggedOut]); + }, [auth, loggedOut, onAfterAuth]); const queryClient = useQueryClient(); diff --git a/airbyte-webapp/src/packages/cloud/views/auth/Auth.tsx b/airbyte-webapp/src/packages/cloud/views/auth/Auth.tsx index d614f6dfd520..7e0886dc9bd4 100644 --- a/airbyte-webapp/src/packages/cloud/views/auth/Auth.tsx +++ b/airbyte-webapp/src/packages/cloud/views/auth/Auth.tsx @@ -37,7 +37,7 @@ const hasValidRightSideUrl = (url?: string): boolean => { export const Auth: React.FC = () => { const { pathname } = useLocation(); const { formatMessage } = useIntl(); - const { loggedOut } = useAuthService(); + const { loggedOut, user } = useAuthService(); const rightSideUrl = useExperiment("authPage.rightSideUrl", undefined); const toLogin = pathname === CloudRoutes.Signup || pathname === CloudRoutes.FirebaseAction; @@ -54,7 +54,17 @@ export const Auth: React.FC = () => { } /> } + element={ + + } /> From e196d89d57938ea79252d00247c55d0cb1ab1dc0 Mon Sep 17 00:00:00 2001 From: tealjulia Date: Wed, 11 Jan 2023 11:43:01 -0500 Subject: [PATCH 3/3] remove redundant check for user --- .../src/packages/cloud/views/auth/Auth.tsx | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/airbyte-webapp/src/packages/cloud/views/auth/Auth.tsx b/airbyte-webapp/src/packages/cloud/views/auth/Auth.tsx index 7e0886dc9bd4..f4852fd0f305 100644 --- a/airbyte-webapp/src/packages/cloud/views/auth/Auth.tsx +++ b/airbyte-webapp/src/packages/cloud/views/auth/Auth.tsx @@ -37,7 +37,7 @@ const hasValidRightSideUrl = (url?: string): boolean => { export const Auth: React.FC = () => { const { pathname } = useLocation(); const { formatMessage } = useIntl(); - const { loggedOut, user } = useAuthService(); + const { loggedOut } = useAuthService(); const rightSideUrl = useExperiment("authPage.rightSideUrl", undefined); const toLogin = pathname === CloudRoutes.Signup || pathname === CloudRoutes.FirebaseAction; @@ -56,13 +56,9 @@ export const Auth: React.FC = () => { path="*" element={ } />