Bernt Christian Egeland 1 месяц назад
Родитель
Сommit
325d124148

+ 11 - 0
prisma/seed_dummy_data.ts

@@ -142,6 +142,17 @@ async function provisionDemoAccount() {
     update: { name: DEMO_ORG_NAME },
   });
 
+  // Belt and braces alongside the demoGuard on org creation: purge any
+  // foreign organizations so the reset always converges on a single org.
+  // Org-scoped rows go with them via ON DELETE CASCADE, and stale
+  // active-org cookies fall back to the demo org membership.
+  const foreignOrgs = await prisma.organization.deleteMany({
+    where: { id: { not: ORG_ID } },
+  });
+  if (foreignOrgs.count > 0) {
+    console.log(`  Removed ${foreignOrgs.count} visitor-created organization(s).`);
+  }
+
   // Owner membership
   await prisma.organizationMember.upsert({
     where: { userId_organizationId: { userId: USER_ID, organizationId: ORG_ID } },

+ 4 - 0
src/features/team/Actions/createNewOrganization.ts

@@ -4,11 +4,15 @@ import { cookies } from "next/headers";
 import { db } from "@/lib/db";
 import { withAuth } from "@/lib/with-auth";
 import { isCloudMode, getMaxOrganizations } from "@/lib/features";
+import { demoGuard } from "@/lib/demo";
 import { createOrganizationSchema } from "../Schema/teamSchema";
 import { revalidatePath } from "next/cache";
 
 export async function createNewOrganization(input: unknown) {
   return withAuth(async ({ userId }) => {
+    // A visitor-created org survives the per-org demo reset and hijacks the
+    // shared demo user's active-org cookie for every later visitor.
+    demoGuard();
     const data = createOrganizationSchema.parse(input);
 
     if (isCloudMode()) {

+ 3 - 0
src/features/team/Actions/teamActions.ts

@@ -59,6 +59,9 @@ export async function getOrganization() {
 
 export async function createOrganization(input: unknown) {
   return withAuth(async ({ userId }) => {
+    // A visitor-created org survives the per-org demo reset and hijacks the
+    // shared demo user's active-org cookie for every later visitor.
+    demoGuard();
     const data = createOrganizationSchema.parse(input);
 
     if (isCloudMode()) {