Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🪟 🎉 Verify auth status on tab focus #21175

Merged
merged 7 commits into from
Jan 12, 2023
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