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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃獰 馃悰 Fix duplicate createUser calls on signup #21454

Merged
merged 8 commits into from
Jan 16, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions airbyte-webapp/src/packages/cloud/services/auth/AuthService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,26 +147,34 @@ export const AuthenticationProvider: React.FC<React.PropsWithChildren<unknown>>
const stateRef = useRef(state);
stateRef.current = state;

useEffectOnce(() => {
return auth.onAuthStateChanged(async (currentUser) => {
// We want to run this effect only once on initial page opening
const onAuthStateChange = useCallback(
josephkmh marked this conversation as resolved.
Show resolved Hide resolved
async (currentUser) => {
if (!stateRef.current.inited) {
josephkmh marked this conversation as resolved.
Show resolved Hide resolved
if (stateRef.current.currentUser === null && currentUser) {
await onAfterAuth(currentUser);
} else {
authInited();
}
}
},
[onAfterAuth, authInited]
);

useEffectOnce(() => {
return auth.onAuthStateChanged(async (currentUser) => {
// We want to run this effect only once on initial page opening
onAuthStateChange(currentUser);
});
});

// Check auth state on window focus, in case the user logged out in a different tab
useEffect(() => {
const onFocus = async () => {
return auth.onAuthStateChanged(async (currentUser) => {
if (!currentUser) {
loggedOut();
} else {
await onAfterAuth(currentUser);
onAuthStateChange(currentUser);
josephkmh marked this conversation as resolved.
Show resolved Hide resolved
}
});
};
Expand All @@ -175,7 +183,7 @@ export const AuthenticationProvider: React.FC<React.PropsWithChildren<unknown>>
return () => {
window.removeEventListener("focus", onFocus);
};
}, [auth, loggedOut, onAfterAuth]);
}, [auth, loggedOut, onAfterAuth, onAuthStateChange]);

const queryClient = useQueryClient();

Expand Down