From e8aaa6149439bc70d7cc2bc39b0df99604bf6700 Mon Sep 17 00:00:00 2001 From: Bee <68532117+abeatrix@users.noreply.github.com> Date: Tue, 22 Jul 2025 20:00:14 -0700 Subject: [PATCH] Improve auth state management for account view (#5107) - Fix AccountView state management when user is not authenticated or is authenticated after the webview is loaded - Add proper loading state reset and conditional data fetching --- .../src/components/account/AccountView.tsx | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/webview-ui/src/components/account/AccountView.tsx b/webview-ui/src/components/account/AccountView.tsx index b2951692..60c90e66 100644 --- a/webview-ui/src/components/account/AccountView.tsx +++ b/webview-ui/src/components/account/AccountView.tsx @@ -149,14 +149,6 @@ export const ClineAccountView = () => { const getUserOrganizations = useCallback(async () => { try { - if (!clineUser?.uid) { - setBalance(null) - setUserOrganizations([]) - setActiveOrganization(null) - setIsSwitchingProfile(false) - setIsLoading(false) - return - } const response = await AccountServiceClient.getUserOrganizations(EmptyRequest.create()) if (response.organizations && !deepEqual(userOrganizations, response.organizations)) { setUserOrganizations(response.organizations) @@ -179,7 +171,7 @@ export const ClineAccountView = () => { } catch (error) { console.error("Failed to fetch user organizations:", error) } - }, [clineUser?.uid, userOrganizations, isSwitchingProfile, activeOrganization?.organizationId]) + }, [userOrganizations, isSwitchingProfile, activeOrganization?.organizationId]) const fetchCreditBalance = useCallback(async () => { try { @@ -277,12 +269,21 @@ export const ClineAccountView = () => { // Handle organization changes and initial load useEffect(() => { + // Reset state when user is not logged in + if (!clineUser?.uid) { + setIsLoading(true) + setBalance(null) + setUserOrganizations([]) + setActiveOrganization(null) + setIsSwitchingProfile(false) + return + } const loadData = async () => { await getUserOrganizations() await fetchCreditBalance() } loadData() - }, [activeOrganization?.organizationId]) + }, [activeOrganization?.organizationId, clineUser?.uid]) // Periodic refresh useEffect(() => { @@ -376,7 +377,11 @@ export const ClineAccountView = () => {
{balance === null ? ---- : } - +