diff --git a/app/(organization)/organizations/[organizationId]/access.ts b/app/(organization)/organizations/[organizationId]/access.ts
index 39190d3..54f3c89 100644
--- a/app/(organization)/organizations/[organizationId]/access.ts
+++ b/app/(organization)/organizations/[organizationId]/access.ts
@@ -36,7 +36,7 @@ export async function requireOrganizationAccess(
requestHeaders.get(CURRENT_PATH_HEADER) ??
`/organizations/${organizationId}`;
- redirect(buildOrganizationsRedirect(currentPath) as Route);
+ redirect(buildOrganizationsRedirect(organizationId, currentPath) as Route);
}
return organizationList;
diff --git a/app/(organization)/organizations/_components/organization-redirect-card.tsx b/app/(organization)/organizations/_components/organization-redirect-card.tsx
new file mode 100644
index 0000000..3e88cb5
--- /dev/null
+++ b/app/(organization)/organizations/_components/organization-redirect-card.tsx
@@ -0,0 +1,143 @@
+"use client";
+
+import { useQueryClient, useSuspenseQuery } from "@tanstack/react-query";
+import { ArrowRight, Loader2 } from "lucide-react";
+import type { Route } from "next";
+import { useRouter } from "next/navigation";
+import { useTransition } from "react";
+import { toast } from "sonner";
+import { MemberRoleBadge } from "@/components/general/member-role-badge";
+import { OrganizationAvatar } from "@/components/general/organization-avatar";
+import {
+ Alert,
+ AlertAction,
+ AlertDescription,
+ AlertTitle,
+} from "@/components/ui/alert";
+import { Badge } from "@/components/ui/badge";
+import { Button } from "@/components/ui/button";
+import {
+ Card,
+ CardContent,
+ CardDescription,
+ CardHeader,
+ CardTitle,
+} from "@/components/ui/card";
+import { Skeleton } from "@/components/ui/skeleton";
+import { authClient } from "@/lib/auth-client";
+import { orpc } from "@/lib/orpc";
+import { useOrganizationRedirectParams } from "../search-params";
+
+export function OrganizationRedirectCard() {
+ const [isPending, startTransition] = useTransition();
+ const [{ organizationId, next }, setParams] = useOrganizationRedirectParams();
+ const {
+ data: { organizations },
+ } = useSuspenseQuery(orpc.organization.list.queryOptions());
+
+ const queryClient = useQueryClient();
+ const router = useRouter();
+
+ if (!organizationId) return null;
+
+ const org = organizations.find((o) => o.id === organizationId);
+ if (!org) return null;
+
+ const role = org.role;
+
+ async function handleSwitch() {
+ if (!organizationId) return;
+ startTransition(async () => {
+ const { data, error } = await authClient.organization.setActive({
+ organizationId,
+ });
+
+ if (error) {
+ toast.error("Failed to switch organization!", {
+ description: error.message ?? "Unknown error",
+ });
+ return;
+ }
+
+ toast.success(
+ `Switched to ${data?.name ?? org?.name ?? "organization"} successfully, Redirecting please wait...`
+ );
+
+ await queryClient.invalidateQueries(
+ orpc.organization.list.queryOptions()
+ );
+
+ router.push((next ?? `/organizations/${organizationId}`) as Route);
+ });
+ }
+
+ function handleCancel() {
+ setParams({ organizationId: null, next: null });
+ }
+
+ return (
+
+
+ Switch to {org?.name}
+
+
+
+
+ You were redirected because your current switched organization does
+ not match the organization you are trying to access.
+
+
+
+
+
+
+