Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(web): ensure active workspace is set when deep-linking to settings

Andrej31cd7e03ebd1
diff --git a/apps/web/src/routes/_layout/_authenticated/dashboard/settings/workspace.tsx b/apps/web/src/routes/_layout/_authenticated/dashboard/settings/workspace.tsx
index ccbd7b033..c96ae4604 100644
--- a/apps/web/src/routes/_layout/_authenticated/dashboard/settings/workspace.tsx
+++ b/apps/web/src/routes/_layout/_authenticated/dashboard/settings/workspace.tsx
@@ -2,6 +2,7 @@ import {
createFileRoute,
Link,
Outlet,
+ redirect,
useLocation,
} from "@tanstack/react-router";
import { Settings, Shield, Users } from "lucide-react";
@@ -15,12 +16,33 @@ import {
SidebarMenu,
SidebarMenuItem,
} from "@/components/ui/sidebar";
+import getWorkspaces from "@/fetchers/workspace/get-workspaces";
import { useWorkspacePermission } from "@/hooks/use-workspace-permission";
+import { authClient } from "@/lib/auth-client";
import { cn } from "@/lib/cn";
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…" — pick the first
+ // workspace as active so the layout has something to render.
+ beforeLoad: async () => {
+ const session = await authClient.getSession();
+ if (session?.data?.session?.activeOrganizationId) return;
+
+ const workspaces = await getWorkspaces();
+ if (workspaces.length === 0) {
+ throw redirect({ to: "/onboarding" });
+ }
+
+ await authClient.organization.setActive({
+ organizationId: workspaces[0].id,
+ });
+ },
component: RouteComponent,
});