Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions apps/app/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ const LANDING_PATH = "/";

const SIGN_IN_PATH = "/sign-in";

const PUBLIC = [SIGN_IN_PATH];

const UNGATED = [SIGN_IN_PATH, "/grant-access", "/eve"];
const UNGATED = ["/grant-access", "/eve"];

const SECTIONS = ["/companies", "/contacts", "/deals", "/settings"];

export async function proxy(request: NextRequest) {
const { pathname } = request.nextUrl;

if (pathname === SIGN_IN_PATH) return NextResponse.next();

if (
getSessionCookie(request, { cookiePrefix: AUTH_COOKIE_PREFIX }) === null
) {
Expand Down Expand Up @@ -71,9 +71,7 @@ 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));
return pathname === LANDING_PATH && isMarketing();
}

function isUngated(pathname: string): boolean {
Expand Down
13 changes: 13 additions & 0 deletions apps/app/test/onboarding-gate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,19 @@ describe("proxy", () => {
expect(redirectedTo(await proxy(request("/sign-in")))).toBeNull();
});

it("never aims a redirect at the sign-in page itself", async () => {
marketing(undefined);
setup({ onboarded: false, configured: false });

expect(redirectedTo(await proxy(request("/sign-in")))).toBeNull();
expect(
redirectedTo(await proxy(request("/sign-in", [SESSION_COOKIE]))),
).toBeNull();
expect(
redirectedTo(await proxy(request("/sign-in?method=google"))),
).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");
Expand Down