aboutsummaryrefslogtreecommitdiff
path: root/apps/web/middleware.ts
diff options
context:
space:
mode:
authorMaheshtheDev <[email protected]>2025-11-11 19:10:13 +0000
committerMaheshtheDev <[email protected]>2025-11-11 19:10:13 +0000
commita88525feb0dcf7d46bebcb87be4125569bb5da3b (patch)
tree3d620bd3e28fb77a559ebf4cc3ffdc46962b128a /apps/web/middleware.ts
parentdocs: personal assistant cookbook update (#575) (diff)
downloadsupermemory-a88525feb0dcf7d46bebcb87be4125569bb5da3b.tar.xz
supermemory-a88525feb0dcf7d46bebcb87be4125569bb5da3b.zip
fix: org switch issue on consumer when dev org exists (#577)11-11-fix_org_switch_issue_on_consumer_when_dev_org_exists
Diffstat (limited to 'apps/web/middleware.ts')
-rw-r--r--apps/web/middleware.ts58
1 files changed, 58 insertions, 0 deletions
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).*)",
+ ],
+}