Skip to content

Commit bdb94a3

Browse files
committed
hotfix(frontend): clear cache account on logout
1 parent 8daec53 commit bdb94a3

File tree

5 files changed

+53
-22
lines changed

5 files changed

+53
-22
lines changed

autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/AccountMenu.tsx

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,32 @@ import {
33
PopoverContent,
44
PopoverTrigger,
55
} from "@/components/__legacy__/ui/popover";
6-
import Link from "next/link";
7-
import * as React from "react";
8-
import { getAccountMenuOptionIcon, MenuItemGroup } from "../../helpers";
9-
import { AccountLogoutOption } from "./components/AccountLogoutOption";
10-
import { PublishAgentModal } from "@/components/contextual/PublishAgentModal/PublishAgentModal";
6+
import { Skeleton } from "@/components/__legacy__/ui/skeleton";
117
import Avatar, {
128
AvatarFallback,
139
AvatarImage,
1410
} from "@/components/atoms/Avatar/Avatar";
11+
import { PublishAgentModal } from "@/components/contextual/PublishAgentModal/PublishAgentModal";
12+
import Link from "next/link";
13+
import * as React from "react";
14+
import { getAccountMenuOptionIcon, MenuItemGroup } from "../../helpers";
15+
import { AccountLogoutOption } from "./components/AccountLogoutOption";
1516

1617
interface Props {
1718
userName?: string;
1819
userEmail?: string;
1920
avatarSrc?: string;
2021
hideNavBarUsername?: boolean;
2122
menuItemGroups: MenuItemGroup[];
23+
isLoading?: boolean;
2224
}
2325

2426
export function AccountMenu({
2527
userName,
2628
userEmail,
2729
avatarSrc,
2830
menuItemGroups,
31+
isLoading = false,
2932
}: Props) {
3033
const popupId = React.useId();
3134

@@ -63,15 +66,24 @@ export function AccountMenu({
6366
</AvatarFallback>
6467
</Avatar>
6568
<div className="relative flex h-[47px] w-[173px] flex-col items-start justify-center gap-1">
66-
<div className="max-w-[10.5rem] truncate font-sans text-base font-semibold leading-none text-white dark:text-neutral-200">
67-
{userName}
68-
</div>
69-
<div
70-
data-testid="account-menu-user-email"
71-
className="max-w-[10.5rem] truncate font-sans text-base font-normal leading-none text-white dark:text-neutral-400"
72-
>
73-
{userEmail}
74-
</div>
69+
{isLoading || !userName || !userEmail ? (
70+
<>
71+
<Skeleton className="h-4 w-24 bg-white/40" />
72+
<Skeleton className="h-4 w-32 bg-white/40" />
73+
</>
74+
) : (
75+
<>
76+
<div className="max-w-[10.5rem] truncate font-sans text-base font-semibold leading-none text-white dark:text-neutral-200">
77+
{userName}
78+
</div>
79+
<div
80+
data-testid="account-menu-user-email"
81+
className="max-w-[10.5rem] truncate font-sans text-base font-normal leading-none text-white dark:text-neutral-400"
82+
>
83+
{userEmail}
84+
</div>
85+
</>
86+
)}
7587
</div>
7688
</div>
7789

autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/components/AccountLogoutOption.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ export function AccountLogoutOption() {
2828
variant: "destructive",
2929
});
3030
} finally {
31-
setIsLoggingOut(false);
31+
setTimeout(() => {
32+
setIsLoggingOut(false);
33+
}, 3000);
3234
}
3335
}
3436

autogpt_platform/frontend/src/components/layout/Navbar/components/NavbarView.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,19 @@ export function NavbarView({ isLoggedIn, previewBranchName }: NavbarViewProps) {
2626
const dynamicMenuItems = getAccountMenuItems(user?.role);
2727
const isChatEnabled = useGetFlag(Flag.CHAT);
2828

29-
const { data: profile } = useGetV2GetUserProfile({
30-
query: {
31-
select: (res) => (res.status === 200 ? res.data : null),
32-
enabled: isLoggedIn,
29+
const { data: profile, isLoading: isProfileLoading } = useGetV2GetUserProfile(
30+
{
31+
query: {
32+
select: (res) => (res.status === 200 ? res.data : null),
33+
enabled: isLoggedIn && !!user,
34+
// Include user ID in query key to ensure cache invalidation when user changes
35+
queryKey: ["/api/store/profile", user?.id],
36+
},
3337
},
34-
});
38+
);
39+
40+
const { isUserLoading } = useSupabase();
41+
const isLoadingProfile = isProfileLoading || isUserLoading;
3542

3643
const linksWithChat = useMemo(() => {
3744
const chatLink = { name: "Chat", href: "/chat" };
@@ -84,6 +91,7 @@ export function NavbarView({ isLoggedIn, previewBranchName }: NavbarViewProps) {
8491
userEmail={profile?.name}
8592
avatarSrc={profile?.avatar_url ?? ""}
8693
menuItemGroups={dynamicMenuItems}
94+
isLoading={isLoadingProfile}
8795
/>
8896
</div>
8997
</div>

autogpt_platform/frontend/src/lib/supabase/hooks/helpers.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ export async function fetchUser(): Promise<FetchUserResult> {
5151
const { user, error } = await getCurrentUser();
5252

5353
if (error || !user) {
54+
// Only mark as loaded if we got an explicit error (not just no user)
55+
// This allows retrying when cookies aren't ready yet after login
5456
return {
5557
user: null,
56-
hasLoadedUser: true,
58+
hasLoadedUser: !!error, // Only true if there was an error, not just no user
5759
isUserLoading: false,
5860
};
5961
}
@@ -68,7 +70,7 @@ export async function fetchUser(): Promise<FetchUserResult> {
6870
console.error("Get user error:", error);
6971
return {
7072
user: null,
71-
hasLoadedUser: true,
73+
hasLoadedUser: true, // Error means we tried and failed, so mark as loaded
7274
isUserLoading: false,
7375
};
7476
}

autogpt_platform/frontend/src/lib/supabase/hooks/useSupabaseStore.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ export const useSupabaseStore = create<SupabaseStoreState>((set, get) => {
140140

141141
broadcastLogout();
142142

143+
// Clear React Query cache to prevent stale data from old user
144+
if (typeof window !== "undefined") {
145+
const { getQueryClient } = await import("@/lib/react-query/queryClient");
146+
const queryClient = getQueryClient();
147+
queryClient.clear();
148+
}
149+
143150
set({
144151
user: null,
145152
hasLoadedUser: false,

0 commit comments

Comments
 (0)