fix: resolve auth/tenant loop and serialization errors

- middleware: remove auth-path→/dashboard redirect; stale session cookies
  caused dashboard→onboarding→sign-in→dashboard infinite loop
- dashboard layout: check getCurrentUser first, redirect to /sign-in
  directly instead of going through /onboarding
- getActiveContext: use admin client (users.listMemberships) for tenant
  resolution instead of session-dependent getUserTeams()
- requireTenant: validate membership before trusting stored tenantId;
  clear stale cookie and re-resolve if user is not a member
- sunum page: JSON.parse/stringify property rows before passing to
  Client Component (Appwrite SDK objects have non-plain prototypes)
This commit is contained in:
egecankomur
2026-05-12 17:18:19 +03:00
parent a3bcb464ea
commit fe86bfe6b2
5 changed files with 34 additions and 13 deletions
+4 -1
View File
@@ -3,7 +3,7 @@ import { Query } from "node-appwrite";
import { getActiveContext } from "@/lib/appwrite/active-context";
import { getLogoUrl } from "@/lib/appwrite/storage";
import { createAdminClient, createSessionClient } from "@/lib/appwrite/server";
import { createAdminClient, createSessionClient, getCurrentUser } from "@/lib/appwrite/server";
import { DATABASE_ID, TABLES } from "@/lib/appwrite/schema";
import type { ThemePrefs } from "@/lib/appwrite/theme-prefs-actions";
import { DashboardShell } from "./dashboard-shell";
@@ -13,6 +13,9 @@ export default async function DashboardLayout({
}: {
children: React.ReactNode;
}) {
const sessionUser = await getCurrentUser();
if (!sessionUser) redirect("/sign-in");
const ctx = await getActiveContext();
if (!ctx) redirect("/onboarding");