From 3c5bf15ffeaa402de130bf6e3b6e09252ef75ee9 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 27 Apr 2026 08:01:56 +0000 Subject: [PATCH] Fetch workspaces when user becomes authenticated The workspace dropdown was empty and no default workspace was selected when navigating to /home (e.g. after login or page refresh) because fetchWorkspaces was only called from Register, AcceptInvitation, and WorkspaceSwitcher's create flow. Drive the fetch from a createEffect on the authenticated user so all entry points populate the dropdown and select a default consistently, and clear the state on logout. --- ui/src/context/WorkspaceProvider.tsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ui/src/context/WorkspaceProvider.tsx b/ui/src/context/WorkspaceProvider.tsx index 01eff00..8fbe1d8 100644 --- a/ui/src/context/WorkspaceProvider.tsx +++ b/ui/src/context/WorkspaceProvider.tsx @@ -1,6 +1,7 @@ import { Accessor, createContext, + createEffect, createMemo, createSignal, JSXElement, @@ -10,6 +11,7 @@ import { import { getWorkspaces } from '../api' import { WorkspaceListItemAttributes } from '../models/Workspace' import type { FrozenReason } from '../models/Workspace' +import { useUser } from './UserProvider' interface WorkspaceContextAttributes { workspaces: Accessor @@ -27,6 +29,7 @@ interface WorkspaceContextAttributes { const WorkspaceContext = createContext(null) export const WorkspaceProvider = (props: { children: JSXElement }) => { + const { user } = useUser() const [workspaces, setWorkspaces] = createSignal< WorkspaceListItemAttributes[] >([]) @@ -78,6 +81,18 @@ export const WorkspaceProvider = (props: { children: JSXElement }) => { localStorage.setItem('currentWorkspaceId', String(workspace.id)) } + // Keep workspaces in sync with the authenticated user so any entry point + // (login, page refresh, deep link) ends up with a populated dropdown and + // a selected workspace without each page having to fetch on its own. + createEffect(() => { + if (user()) { + void fetchWorkspaces() + } else { + setWorkspaces([]) + setCurrentWorkspace(null) + } + }) + return (