From a88525feb0dcf7d46bebcb87be4125569bb5da3b Mon Sep 17 00:00:00 2001 From: MaheshtheDev <38828053+MaheshtheDev@users.noreply.github.com> Date: Tue, 11 Nov 2025 19:10:13 +0000 Subject: fix: org switch issue on consumer when dev org exists (#577) --- apps/web/middleware.ts | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ apps/web/package.json | 4 ++-- apps/web/proxy.ts | 58 -------------------------------------------------- 3 files changed, 60 insertions(+), 60 deletions(-) create mode 100644 apps/web/middleware.ts delete mode 100644 apps/web/proxy.ts (limited to 'apps') diff --git a/apps/web/middleware.ts b/apps/web/middleware.ts new file mode 100644 index 00000000..bbb63c42 --- /dev/null +++ b/apps/web/middleware.ts @@ -0,0 +1,58 @@ +import { getSessionCookie } from "better-auth/cookies" +import { NextResponse } from "next/server" + +export default async function proxy(request: Request) { + console.debug("[PROXY] === PROXY START ===") + const url = new URL(request.url) + console.debug("[PROXY] Path:", url.pathname) + console.debug("[PROXY] Method:", request.method) + + const sessionCookie = getSessionCookie(request) + console.debug("[PROXY] Session cookie exists:", !!sessionCookie) + + // Always allow access to login and waitlist pages + const publicPaths = ["/login"] + if (publicPaths.includes(url.pathname)) { + console.debug("[PROXY] Public path, allowing access") + return NextResponse.next() + } + + // If no session cookie and not on a public path, redirect to login + if (!sessionCookie) { + console.debug( + "[PROXY] No session cookie and not on public path, redirecting to /login", + ) + const url = new URL("/login", request.url) + url.searchParams.set("redirect", request.url) + return NextResponse.redirect(url) + } + + // TEMPORARILY DISABLED: Waitlist check + // if (url.pathname !== "/waitlist") { + // const response = await $fetch("@get/waitlist/status", { + // headers: { + // Authorization: `Bearer ${sessionCookie}`, + // }, + + // console.debug("[PROXY] Waitlist status:", response.data); + // if (response.data && !response.data.accessGranted) { + // return NextResponse.redirect(new URL("/waitlist", request.url)); + // } + // } + + console.debug("[PROXY] Passing through to next handler") + console.debug("[PROXY] === PROXY END ===") + const response = NextResponse.next() + response.cookies.set({ + name: "last-site-visited", + value: "https://app.supermemory.ai", + domain: "supermemory.ai", + }) + return response +} + +export const config = { + matcher: [ + "/((?!_next/static|_next/image|images|icon.png|monitoring|opengraph-image.png|ingest|api|login|api/emails).*)", + ], +} diff --git a/apps/web/package.json b/apps/web/package.json index 46bfa8fb..24f9f88f 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -22,7 +22,7 @@ "@dnd-kit/modifiers": "^9.0.0", "@dnd-kit/sortable": "^10.0.0", "@dnd-kit/utilities": "^3.2.2", - "@opennextjs/cloudflare": "^1.6.1", + "@opennextjs/cloudflare": "^1.12.0", "@radix-ui/react-accordion": "^1.2.11", "@radix-ui/react-alert-dialog": "^1.1.14", "@radix-ui/react-avatar": "^1.1.10", @@ -59,7 +59,7 @@ "embla-carousel-autoplay": "^8.6.0", "embla-carousel-react": "^8.6.0", "framer-motion": "^12.23.12", - "idb-keyval": "^6.2.2", + "idb-keyval": "^6.2.2", "is-hotkey": "^0.2.0", "lucide-react": "^0.525.0", "masonic": "^4.1.0", diff --git a/apps/web/proxy.ts b/apps/web/proxy.ts deleted file mode 100644 index 375b0c73..00000000 --- a/apps/web/proxy.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { getSessionCookie } from "better-auth/cookies" -import { NextResponse } from "next/server" - -export default async function proxy(request: Request) { - console.debug("[PROXY] === PROXY START ===") - const url = new URL(request.url) - console.debug("[PROXY] Path:", url.pathname) - console.debug("[PROXY] Method:", request.method) - - const sessionCookie = getSessionCookie(request) - console.debug("[PROXY] Session cookie exists:", !!sessionCookie) - - // Always allow access to login and waitlist pages - const publicPaths = ["/login"] - if (publicPaths.includes(url.pathname)) { - console.debug("[PROXY] Public path, allowing access") - return NextResponse.next() - } - - // If no session cookie and not on a public path, redirect to login - if (!sessionCookie) { - console.debug( - "[PROXY] No session cookie and not on public path, redirecting to /login", - ) - const url = new URL("/login", request.url) - url.searchParams.set("redirect", request.url) - return NextResponse.redirect(url) - } - - // TEMPORARILY DISABLED: Waitlist check - // if (url.pathname !== "/waitlist") { - // const response = await $fetch("@get/waitlist/status", { - // headers: { - // Authorization: `Bearer ${sessionCookie}`, - // }, - // }); - // console.debug("[PROXY] Waitlist status:", response.data); - // if (response.data && !response.data.accessGranted) { - // return NextResponse.redirect(new URL("/waitlist", request.url)); - // } - // } - - console.debug("[PROXY] Passing through to next handler") - console.debug("[PROXY] === PROXY END ===") - const response = NextResponse.next() - response.cookies.set({ - name: "last-site-visited", - value: "https://app.supermemory.ai", - domain: "supermemory.ai", - }) - return response -} - -export const config = { - matcher: [ - "/((?!_next/static|_next/image|images|icon.png|monitoring|opengraph-image.png|ingest|api|login|api/emails).*)", - ], -} -- cgit v1.2.3