Comp AI CRM is an open source, CRM designed for AI agents. Agentic-first CRM.
TypeScript
feat(proxy): implement marketing flag for landing page visibility
Lewis Carhart81a36d66da79
diff --git a/apps/app/lib/env.ts b/apps/app/lib/env.tsindex 30b75b39..bd02b96a 100644--- a/apps/app/lib/env.ts+++ b/apps/app/lib/env.ts@@ -1,2 +1,6 @@export const API_URL =process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:3001";++export function isMarketing(): boolean {+ return process.env.IS_MARKETING === "true";+}diff --git a/apps/app/proxy.ts b/apps/app/proxy.tsindex 79dff2d8..7d982aaa 100644--- a/apps/app/proxy.ts+++ b/apps/app/proxy.ts@@ -1,6 +1,7 @@import { AUTH_COOKIE_PREFIX } from "@crm/auth/cookies";import { getSessionCookie } from "better-auth/cookies";import { type NextRequest, NextResponse } from "next/server";+import { isMarketing } from "@/lib/env";import {ONBOARDING_PATH,RESEARCH_PATH,@@ -13,7 +14,7 @@ const LANDING_PATH = "/";const SIGN_IN_PATH = "/sign-in";-const PUBLIC = [LANDING_PATH, SIGN_IN_PATH];+const PUBLIC = [SIGN_IN_PATH];const UNGATED = [SIGN_IN_PATH, "/grant-access", "/eve"];@@ -70,6 +71,8 @@ function isUnder(pathname: string, prefix: string): boolean {}function isPublic(pathname: string): boolean {+ if (pathname === LANDING_PATH) return isMarketing();+return PUBLIC.some((prefix) => isUnder(pathname, prefix));}diff --git a/apps/app/test/onboarding-gate.spec.ts b/apps/app/test/onboarding-gate.spec.tsindex 72f1b7d8..42122b76 100644--- a/apps/app/test/onboarding-gate.spec.ts+++ b/apps/app/test/onboarding-gate.spec.ts@@ -10,10 +10,18 @@ const SLUG = "comp-ai";const realFetch = globalThis.fetch;+const realMarketing = process.env.IS_MARKETING;+afterEach(() => {globalThis.fetch = realFetch;+ marketing(realMarketing);});+function marketing(value: string | undefined) {+ if (value === undefined) delete process.env.IS_MARKETING;+ else process.env.IS_MARKETING = value;+}+function stub(handler: (url: string) => Promise<Response>) {globalThis.fetch = ((input: string | URL | Request) =>handler(String(input))) as unknown as typeof fetch;@@ -145,6 +153,8 @@ describe("readResearchGate", () => {describe("proxy", () => {it("shows a stranger the landing page and nothing behind it", async () => {+ marketing("true");+expect(redirectedTo(await proxy(request("/")))).toBeNull();expect(redirectedTo(await proxy(request("/sign-in")))).toBeNull();expect(redirectedTo(await proxy(request(`/${SLUG}`)))).toBe("/sign-in");@@ -153,6 +163,24 @@ describe("proxy", () => {);});+ it("sends a stranger to sign in when the install has no landing page", async () => {+ marketing(undefined);++ expect(redirectedTo(await proxy(request("/")))).toBe("/sign-in");+ expect(redirectedTo(await proxy(request("/sign-in")))).toBeNull();+ });++ it("reads the flag on every request, and only the literal true turns it on", async () => {+ marketing("false");+ expect(redirectedTo(await proxy(request("/")))).toBe("/sign-in");++ marketing("1");+ expect(redirectedTo(await proxy(request("/")))).toBe("/sign-in");++ marketing("true");+ expect(redirectedTo(await proxy(request("/")))).toBeNull();+ });+it("ignores a neighbour's cookie from the parent domain", async () => {expect(AUTH_COOKIE_PREFIX).not.toBe("better-auth");setup();diff --git a/apps/app/turbo.json b/apps/app/turbo.jsonindex 4e931705..5b82d363 100644--- a/apps/app/turbo.json+++ b/apps/app/turbo.json@@ -14,7 +14,8 @@"AUTH_TRUSTED_ORIGINS","BETTER_AUTH_SECRET","BETTER_AUTH_URL",- "DATABASE_URL"+ "DATABASE_URL",+ "IS_MARKETING"]},"dev": {@@ -28,6 +29,7 @@"BETTER_AUTH_SECRET","BETTER_AUTH_URL","DATABASE_URL",+ "IS_MARKETING","NEXT_PUBLIC_API_URL","NEXT_PUBLIC_AUTH_URL"]