Skip to content

Commit

Permalink
🪟 🎉 Verify auth status on tab focus (#21175)
Browse files Browse the repository at this point in the history
  • Loading branch information
teallarson authored Jan 12, 2023
1 parent 2dc5b2f commit 80f3c4e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
19 changes: 18 additions & 1 deletion airbyte-webapp/src/packages/cloud/services/auth/AuthService.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -160,6 +160,23 @@ export const AuthenticationProvider: React.FC<React.PropsWithChildren<unknown>>
});
});

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(
Expand Down
8 changes: 7 additions & 1 deletion airbyte-webapp/src/packages/cloud/views/auth/Auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ export const Auth: React.FC = () => {
<Route path={CloudRoutes.FirebaseAction} element={<FirebaseActionRoute />} />
<Route
path="*"
element={<Navigate to={`${CloudRoutes.Login}${loggedOut ? "" : `?from=${pathname}`}`} />}
element={
<Navigate
to={`${CloudRoutes.Login}${
loggedOut && pathname.includes("/settings/account") ? "" : `?from=${pathname}`
}`}
/>
}
/>
</Routes>
</Suspense>
Expand Down

0 comments on commit 80f3c4e

Please sign in to comment.