Skip to content

Commit

Permalink
feat: clean up UI state on disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
bswags committed Jul 12, 2024
1 parent 90e9b79 commit cc706e1
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions account-kit/react/src/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,19 @@ export const AlchemyAccountProvider = (
}
}, [status, config.ui, openAuthModal]);

// Force the auth UI back to the initial state when disconnected
useEffect(() => {
if (status === "DISCONNECTED" && !isAuthenticating) {
setAuthStep({ type: "initial" });
// Remove the relevant query params (could also do this once connected)
const url = new URL(window.location.href);
url.searchParams.delete("orgId");
url.searchParams.delete("bundle");
url.searchParams.delete(IS_SIGNUP_QP);
window.history.replaceState({}, "", url.toString());
}
}, [status, isAuthenticating]);

return (
<Hydrate {...props}>
<AlchemyAccountContext.Provider value={initialContext}>
Expand Down

0 comments on commit cc706e1

Please sign in to comment.