⚡ 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
import { createFileRoute, redirect } from "@tanstack/react-router";
import { getPendingInvitations } from "@/fetchers/invitation/get-pending-invitations";
import getWorkspaces from "@/fetchers/workspace/get-workspaces";
import { authClient } from "@/lib/auth-client";
import { handleUnauthorized, isUnauthorizedError } from "@/lib/http-error";
import type Workspace from "@/types/workspace";
export const Route = createFileRoute("/_layout/_authenticated/dashboard/")({
beforeLoad: async () => {
let workspaces: Workspace[];
let invitations: Awaited<ReturnType<typeof getPendingInvitations>>;
let session: Awaited<ReturnType<typeof authClient.getSession>>;
try {
[workspaces, invitations, session] = await Promise.all([
getWorkspaces(),
getPendingInvitations(),
authClient.getSession(),
]);
} catch (error) {
if (isUnauthorizedError(error)) {
handleUnauthorized();
return;
}
throw error;
}
if (invitations && invitations.length > 0 && !workspaces.length) {
throw redirect({ to: "/invitations" });
}
const activeWorkspaceId = session?.data?.session?.activeOrganizationId;
if (workspaces && workspaces.length > 0) {
if (
activeWorkspaceId &&
workspaces.some((ws) => ws.id === activeWorkspaceId)
) {
throw redirect({
to: "/dashboard/workspace/$workspaceId",
params: { workspaceId: activeWorkspaceId },
});
}
const firstWorkspace = workspaces[0];
authClient.organization.setActive({
organizationId: firstWorkspace.id,
});
throw redirect({
to: "/dashboard/workspace/$workspaceId",
params: { workspaceId: firstWorkspace.id },
});
}
throw redirect({ to: "/onboarding" });
},
});