⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix(web): track session-fetch failure and skip setActive fallback
justin6d8d2a6ae768
diff --git a/apps/web/src/routes/_layout/_authenticated.tsx b/apps/web/src/routes/_layout/_authenticated.tsxindex 080dadce9..496baa155 100644--- a/apps/web/src/routes/_layout/_authenticated.tsx+++ b/apps/web/src/routes/_layout/_authenticated.tsx@@ -5,14 +5,18 @@ import { authClient } from "@/lib/auth-client";export const Route = createFileRoute("/_layout/_authenticated")({beforeLoad: async ({ location }) => {let session = null;+ let sessionError = false;try {const { data } = await authClient.getSession();session = data;} catch (error) {+ sessionError = true;if (import.meta.env.DEV) console.warn("getSession failed", error);- // getSession() rejected (e.g. network error) — treat as unauthenticated+ // getSession() rejected (e.g. network error) — session state is+ // unknown. Don't conflate with "no session" (unauthenticated): let+ // children decide whether to skip active-organization mutations.}- if (!session) {+ if (!session && !sessionError) {throw redirect({to: "/auth/sign-in",search: {@@ -20,6 +24,6 @@ export const Route = createFileRoute("/_layout/_authenticated")({},});}- return { session };+ return { session, sessionError };},});diff --git a/apps/web/src/routes/_layout/_authenticated/dashboard/settings/workspace.tsx b/apps/web/src/routes/_layout/_authenticated/dashboard/settings/workspace.tsxindex 0efa486c6..2c9f7b242 100644--- a/apps/web/src/routes/_layout/_authenticated/dashboard/settings/workspace.tsx+++ b/apps/web/src/routes/_layout/_authenticated/dashboard/settings/workspace.tsx@@ -23,28 +23,36 @@ import { useWorkspacePermission } from "@/hooks/use-workspace-permission";import { authClient } from "@/lib/auth-client";import { cn } from "@/lib/cn";import { getInitials } from "@/lib/get-initials";+import type Workspace from "@/types/workspace";export const Route = createFileRoute("/_layout/_authenticated/dashboard/settings/workspace",)({- // Settings pages live outside `/dashboard/workspace/$workspaceId`, so they- // have no route param to identify "which workspace". They rely on the- // session's active organization. A user who deep-links here (or refreshes)- // before ever visiting a workspace dashboard would otherwise see an empty- // sidebar ("WS / Roles.Undefined") and a stuck "Loading…", so pick the first- // workspace as active so the layout has something to render.- beforeLoad: async () => {- let session = null;+ beforeLoad: async ({ context }) => {+ // Settings pages live outside `/dashboard/workspace/$workspaceId`, so they+ // have no route param to identify "which workspace". They rely on the+ // session's active organization. A user who deep-links here (or refreshes)+ // before ever visiting a workspace dashboard would otherwise see an empty+ // sidebar ("WS / Roles.Undefined") and a stuck "Loading…", so pick the first+ // workspace as active so the layout has something to render.+ //+ // The parent route reports whether the session fetch succeeded. When it+ // failed we don't know the user's current active organization, so we must+ // skip the fallback — calling `setActive` would clobber whatever the user+ // already had selected. Only select the first workspace after a successful+ // session response confirms that no active organization is set.+ if (context.sessionError) return;+ const session = context.session;+ if (!session) return; // parent should have redirected unauthenticated users+ if (session.session?.activeOrganizationId) return;++ let workspaces: Workspace[] = [];try {- const { data } = await authClient.getSession();- session = data;+ workspaces = await getWorkspaces();} catch (error) {- if (import.meta.env.DEV) console.warn("getSession failed", error);- // getSession() rejected (e.g. network error) — continue to workspace fallback+ if (import.meta.env.DEV) console.warn("getWorkspaces failed", error);+ throw redirect({ to: "/onboarding" });}- if (session?.session?.activeOrganizationId) return;-- const workspaces = await getWorkspaces();if (workspaces.length === 0) {throw redirect({ to: "/onboarding" });}