create-ailk 0.35.1 → 0.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/README.md +1 -1
  2. package/component-catalog.json +12 -1
  3. package/component-catalog.md +6 -5
  4. package/dist/lib/env-catalog.js +8 -0
  5. package/dist/surfaces.js +6 -3
  6. package/dist/topology.d.ts +4 -4
  7. package/dist/topology.js +104 -60
  8. package/package.json +3 -3
  9. package/templates/.env.example +21 -0
  10. package/templates/apps/api/.env.example +7 -0
  11. package/templates/apps/api/CLAUDE.md +9 -4
  12. package/templates/apps/mcp/CLAUDE.md +4 -2
  13. package/templates/apps/web/.env.example +16 -0
  14. package/templates/apps/web/CLAUDE.md +46 -5
  15. package/templates/apps/web/app/[locale]/(auth)/__tests__/password-reset.test.tsx +2 -0
  16. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/page.test.tsx +52 -1
  17. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/remembered-method.test.ts +43 -0
  18. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/sign-in-card.test.tsx +108 -1
  19. package/templates/apps/web/app/[locale]/(auth)/sign-in/page.tsx +36 -3
  20. package/templates/apps/web/app/[locale]/(auth)/sign-in/remembered-method.ts +37 -0
  21. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-card.tsx +90 -33
  22. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-text.ts +9 -4
  23. package/templates/apps/web/app/[locale]/(authed)/__tests__/gate.test.tsx +79 -348
  24. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +12 -1
  25. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +55 -2
  26. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout-sign-out.test.tsx +10 -5
  27. package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +1 -1
  28. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +60 -6
  29. package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +32 -3
  30. package/templates/apps/web/app/[locale]/(authed)/account/connect/__tests__/page.test.tsx +8 -1
  31. package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +7 -3
  32. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/phone-verification.test.tsx +215 -0
  33. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/seam-imports.test.ts +65 -0
  34. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +47 -0
  35. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-actions.ts +122 -0
  36. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +214 -0
  37. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/invitation-id.test.ts +35 -0
  38. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/page.test.tsx +266 -0
  39. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/actions.ts +116 -0
  40. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/invitation-id.ts +12 -0
  41. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +154 -0
  42. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +6 -4
  43. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +3 -1
  44. package/templates/apps/web/app/[locale]/(authed)/layout.tsx +15 -13
  45. package/templates/apps/web/app/[locale]/(authed)/signed-out-gate.generated.tsx +20 -52
  46. package/templates/apps/web/app/[locale]/layout.tsx +24 -75
  47. package/templates/apps/web/app/[locale]/purchase/__tests__/success.test.tsx +50 -0
  48. package/templates/apps/web/app/[locale]/purchase/success/page.tsx +48 -7
  49. package/templates/apps/web/app/api/auth/hub/__tests__/entry-routes.test.ts +749 -0
  50. package/templates/apps/web/app/api/auth/hub/authorize/__tests__/route.test.ts +166 -7
  51. package/templates/apps/web/app/api/auth/hub/authorize/route.ts +96 -30
  52. package/templates/apps/web/app/api/auth/hub/continuation.ts +51 -2
  53. package/templates/apps/web/app/api/auth/hub/email/route.ts +111 -0
  54. package/templates/apps/web/app/api/auth/hub/entry-shared.ts +163 -0
  55. package/templates/apps/web/app/api/auth/hub/purchase/route.ts +230 -0
  56. package/templates/apps/web/app/api/auth/hub/purchase-link/route.ts +174 -0
  57. package/templates/apps/web/app/api/auth/hub/sign-up/route.ts +60 -0
  58. package/templates/apps/web/app/api/auth/hub/sign-up-evidence.ts +97 -0
  59. package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +475 -7
  60. package/templates/apps/web/app/api/hub-session/callback/route.ts +13 -47
  61. package/templates/apps/web/app/api/hub-session/email/route.ts +125 -0
  62. package/templates/apps/web/app/api/hub-session/one-tap/nonce/route.ts +49 -0
  63. package/templates/apps/web/app/api/hub-session/one-tap/route.ts +106 -0
  64. package/templates/apps/web/app/api/hub-session/open/route.ts +111 -0
  65. package/templates/apps/web/app/api/hub-session/sign-in/route.ts +23 -40
  66. package/templates/apps/web/app/api/hub-session/sign-out/route.ts +1 -10
  67. package/templates/apps/web/auth.ts +133 -6
  68. package/templates/apps/web/components/sign-out-trigger.tsx +1 -1
  69. package/templates/apps/web/lib/__tests__/auth-email.test.ts +141 -0
  70. package/templates/apps/web/lib/__tests__/auth-phone.test.ts +445 -0
  71. package/templates/apps/web/lib/__tests__/auth-sms.test.ts +140 -0
  72. package/templates/apps/web/lib/__tests__/fixtures/tsconfig.flow.json +18 -0
  73. package/templates/apps/web/lib/__tests__/site-header.test.ts +13 -0
  74. package/templates/apps/web/lib/__tests__/telemetry-scrub.test.ts +19 -1
  75. package/templates/apps/web/lib/auth-email.ts +62 -6
  76. package/templates/apps/web/lib/auth-env.ts +13 -0
  77. package/templates/apps/web/lib/auth-sms.ts +180 -0
  78. package/templates/apps/web/lib/hub-session/__tests__/hub-session.test.ts +28 -0
  79. package/templates/apps/web/lib/hub-session/__tests__/spoke-sign-in.test.tsx +332 -0
  80. package/templates/apps/web/lib/hub-session/config.ts +7 -1
  81. package/templates/apps/web/lib/hub-session/entry.ts +238 -0
  82. package/templates/apps/web/lib/hub-session/index.ts +1 -4
  83. package/templates/apps/web/lib/hub-session/one-tap.tsx +148 -0
  84. package/templates/apps/web/lib/hub-session/session.ts +120 -2
  85. package/templates/apps/web/lib/hub-session/spoke-sign-in.tsx +277 -0
  86. package/templates/apps/web/lib/site-header.ts +14 -1
  87. package/templates/apps/web/lib/telemetry-scrub.ts +11 -0
  88. package/templates/apps/web/lib/topology.generated.ts +39 -0
  89. package/templates/apps/web/messages/en.json +112 -20
  90. package/templates/apps/web/middleware.ts +34 -2
  91. package/templates/apps/web/security-headers.config.ts +21 -0
  92. package/versions.json +47 -47
  93. package/templates/apps/web/app/[locale]/(authed)/sign-in-gate.tsx +0 -162
  94. package/templates/apps/web/components/signed-in-nav.tsx +0 -79
  95. package/templates/apps/web/lib/hub-session/__tests__/sign-in-gate.test.tsx +0 -180
  96. package/templates/apps/web/lib/hub-session/sign-in-gate.tsx +0 -162
@@ -2,28 +2,20 @@
2
2
  * Tests for the `(authed)` group's session guard (#4665 D9, AC7).
3
3
  *
4
4
  * Covers:
5
- * 1. No session → AuthedLayout renders SignInGate.
6
- * 2. A session → AuthedLayout renders its children.
7
- * 3. SignInGate with active providers → renders AuthPanel with those providers.
8
- * 4. SignInGate with zero active providers → renders an EmptyState.
9
- * 5. AILK_AUTH_REQUIRED has no effect on the guard (D9/AC7).
10
- * 6. SignInGate links to `/sign-in?next=<pathname>` in both the providers
11
- * and the zero-provider branches (#4984).
12
- * 7. The providers are resolved on the SERVER, from the real provider env,
13
- * by the layout and handed to the client gate as a prop — the gate reads
14
- * no env of its own (#7419: in the browser that env is always empty, so
15
- * the gate always claimed "Sign-in is not configured").
16
- * 8. With the email sign-in link on (#7435 § D9), the gate composes the
17
- * sign-in card — Google + "Email me a sign-in link" — in place of
18
- * AuthPanel and its inert password form; off, it renders as before.
19
- * 9. On an account path (#7430) the gate speaks to members — the
20
- * `account.gate` copy, never `waitlistDashboard.gate` — and its
21
- * not-configured headline is a real heading element.
22
- * 10. The member gate renders the one card (#9662): `/sign-in`'s card with
23
- * the site's mark, the toggle line to /sign-up and the Terms + Privacy
24
- * acknowledgement.
5
+ * 1. A session → AuthedLayout renders its children, in the app profile root.
6
+ * 2. No session → AuthedLayout redirects to `/sign-in?next=<requested path>`
7
+ * (#11095 D3 AC-4) — on an account path and an operator path alike, with
8
+ * the locale prefix kept and the path encoded. With no `x-pathname`, the
9
+ * redirect is the bare `/sign-in`.
10
+ * 3. AILK_AUTH_REQUIRED has no effect on the guard (D9/AC7).
11
+ * 4. The one in-place render (#7430): an account path on a hub with no
12
+ * sign-in method on keeps the "Sign-in isn't available yet" block, in
13
+ * the member-facing `account.gate` copy, with one action back to the
14
+ * site — `/sign-in` would show only an inert card there.
15
+ * 5. The operator `SignInGate` (`sign-in-gate.tsx`) and its "Go to the
16
+ * sign-in page" link (#4984) are gone (#11095 AC-4).
25
17
  */
26
- import { readFileSync } from "node:fs";
18
+ import { existsSync } from "node:fs";
27
19
  import { join } from "node:path";
28
20
 
29
21
  import { render, screen } from "@testing-library/react";
@@ -40,7 +32,7 @@ jest.mock("next-intl/server", () => ({
40
32
  // mock the locale layout's suite uses (production reads the baked env var).
41
33
  jest.mock("@working-theory/web-i18n", () => ({
42
34
  __esModule: true,
43
- readLocales: jest.fn().mockReturnValue(["en"]),
35
+ readLocales: jest.fn().mockReturnValue(["en", "fr"]),
44
36
  }));
45
37
 
46
38
  // The request's `x-pathname` (forwarded by middleware.ts) — unset by default,
@@ -64,20 +56,16 @@ jest.mock("../../../../auth", () => ({
64
56
  },
65
57
  }));
66
58
 
67
- const mockUsePathname = jest.fn();
59
+ // Next's `redirect()` throws NEXT_REDIRECT; the mock does too, so a layout
60
+ // that rendered instead of redirecting resolves and fails the case.
68
61
  jest.mock("next/navigation", () => ({
69
62
  __esModule: true,
70
- usePathname: () => mockUsePathname(),
71
- }));
72
-
73
- const mockSignInSocial = jest.fn();
74
- jest.mock("better-auth/react", () => ({
75
- __esModule: true,
76
- createAuthClient: () => ({ signIn: { social: mockSignInSocial } }),
63
+ redirect: (url: string): never => {
64
+ throw new Error(`NEXT_REDIRECT ${url}`);
65
+ },
77
66
  }));
78
67
 
79
68
  import AuthedLayout from "../layout";
80
- import { SignInGate } from "../sign-in-gate";
81
69
 
82
70
  // The provider env `lib/auth-env` reads. The layout tests drive it for real —
83
71
  // no mock of auth-env — so they exercise the server-side resolution end to end.
@@ -100,6 +88,8 @@ beforeEach(() => {
100
88
  process.env = { ...ORIGINAL_ENV };
101
89
  for (const key of PROVIDER_ENV_KEYS) delete process.env[key];
102
90
  mockRequestPathname = undefined;
91
+ mockGetSession.mockReset();
92
+ jest.mocked(getTranslations).mockClear();
103
93
  });
104
94
 
105
95
  afterAll(() => {
@@ -111,30 +101,22 @@ function configureGoogle(): void {
111
101
  process.env.GOOGLE_CLIENT_SECRET = "google-client-secret";
112
102
  }
113
103
 
114
- describe("AuthedLayout — the (authed) session guard", () => {
115
- beforeEach(() => {
116
- mockGetSession.mockReset();
117
- mockUsePathname.mockReset().mockReturnValue("/en/waitlist");
118
- configureGoogle();
119
- });
104
+ function configureEmailLink(): void {
105
+ process.env.AUTH_EMAIL_WEBHOOK_SECRET = "webhook-secret";
106
+ process.env.AUTH_EMAIL_FROM = "noreply@example.test";
107
+ process.env.BETTER_AUTH_URL = "https://site.example";
108
+ process.env.BETTER_AUTH_SECRET = "a-real-secret";
109
+ }
120
110
 
121
- it("renders SignInGate when there is no session", async () => {
122
- mockGetSession.mockResolvedValue(null);
123
- const element = await AuthedLayout({
124
- params: Promise.resolve({ locale: "en" }),
125
- children: <div data-testid="dashboard-content" />,
126
- });
127
- render(element);
128
- expect(screen.getByTestId("sign-in-gate")).toBeInTheDocument();
129
- expect(screen.queryByTestId("dashboard-content")).not.toBeInTheDocument();
130
- // #4984 — the layout wires the sign-in link: `localeHref("en", "/sign-in")`
131
- // + the current pathname as `?next=`.
132
- expect(screen.getByTestId("sign-in-gate-link")).toHaveAttribute(
133
- "href",
134
- "/sign-in?next=%2Fen%2Fwaitlist",
135
- );
111
+ function signedOutLayout(locale = "en"): ReturnType<typeof AuthedLayout> {
112
+ mockGetSession.mockResolvedValue(null);
113
+ return AuthedLayout({
114
+ params: Promise.resolve({ locale }),
115
+ children: <div data-testid="dashboard-content" />,
136
116
  });
117
+ }
137
118
 
119
+ describe("AuthedLayout — the (authed) session guard", () => {
138
120
  it("renders children when a session exists", async () => {
139
121
  mockGetSession.mockResolvedValue({ user: { id: "user_1" } });
140
122
  const element = await AuthedLayout({
@@ -143,11 +125,10 @@ describe("AuthedLayout — the (authed) session guard", () => {
143
125
  });
144
126
  render(element);
145
127
  expect(screen.getByTestId("dashboard-content")).toBeInTheDocument();
146
- expect(screen.queryByTestId("sign-in-gate")).not.toBeInTheDocument();
147
128
  });
148
129
 
149
130
  // #5953 AC-1, web half — the app profile applies to the signed-in editor
150
- // surfaces only; SignInGate stays on the marketing profile.
131
+ // surfaces only.
151
132
  it('wraps the signed-in children in a data-profile="app" root', async () => {
152
133
  mockGetSession.mockResolvedValue({ user: { id: "user_1" } });
153
134
  const element = await AuthedLayout({
@@ -162,234 +143,55 @@ describe("AuthedLayout — the (authed) session guard", () => {
162
143
 
163
144
  it("ignores AILK_AUTH_REQUIRED entirely — never read by the guard", async () => {
164
145
  process.env.AILK_AUTH_REQUIRED = "0";
165
- mockGetSession.mockResolvedValue(null);
166
- const element = await AuthedLayout({
167
- params: Promise.resolve({ locale: "en" }),
168
- children: <div data-testid="dashboard-content" />,
169
- });
170
- render(element);
171
- expect(screen.getByTestId("sign-in-gate")).toBeInTheDocument();
172
- });
173
-
174
- // ── #7419 — providers resolved server-side, from the real env ─────────────
175
-
176
- it("renders the Google sign-in control when Google is configured server-side (#7419 AC-1)", async () => {
177
- mockGetSession.mockResolvedValue(null);
178
- const element = await AuthedLayout({
179
- params: Promise.resolve({ locale: "en" }),
180
- children: <div data-testid="dashboard-content" />,
181
- });
182
- render(element);
183
- expect(screen.getByTestId("auth-panel-provider-google")).toBeInTheDocument();
184
- expect(screen.queryByTestId("auth-panel-provider-github")).not.toBeInTheDocument();
185
- expect(screen.queryByTestId("sign-in-gate-empty")).not.toBeInTheDocument();
186
- });
187
-
188
- it("renders the not-configured EmptyState when no provider is configured (#7419 AC-2)", async () => {
189
- for (const key of PROVIDER_ENV_KEYS) delete process.env[key];
190
- mockGetSession.mockResolvedValue(null);
191
- const element = await AuthedLayout({
192
- params: Promise.resolve({ locale: "en" }),
193
- children: <div data-testid="dashboard-content" />,
194
- });
195
- render(element);
196
- expect(screen.getByTestId("sign-in-gate-empty")).toBeInTheDocument();
197
- expect(screen.getByText("copy:emptyHeadline")).toBeInTheDocument();
198
- expect(screen.queryByTestId("auth-panel-card")).not.toBeInTheDocument();
199
- });
200
-
201
- it("filters an unsupported provider id out before handing providers to the gate", async () => {
202
- for (const key of PROVIDER_ENV_KEYS) delete process.env[key];
203
- // "email" is reported by getActiveProviderIds but is not a supported
204
- // AuthPanel provider (google | github) — treated as zero active providers.
205
- process.env.AUTH_EMAIL_SERVER = "smtp://mail.example.test";
206
- process.env.AUTH_EMAIL_FROM = "noreply@example.test";
207
- mockGetSession.mockResolvedValue(null);
208
- const element = await AuthedLayout({
209
- params: Promise.resolve({ locale: "en" }),
210
- children: <div data-testid="dashboard-content" />,
211
- });
212
- render(element);
213
- expect(screen.getByTestId("sign-in-gate-empty")).toBeInTheDocument();
214
- });
215
- });
216
-
217
- const GATE_LABELS = {
218
- emptyHeadline: "No providers",
219
- emptyDescription: "Configure one",
220
- signInLinkLabel: "Go to the sign-in page",
221
- };
222
-
223
- describe("<SignInGate/> — the dashboard's own front door", () => {
224
- beforeEach(() => {
225
- mockUsePathname.mockReset().mockReturnValue("/en/waitlist");
226
- mockSignInSocial.mockReset();
227
- });
228
-
229
- it("renders AuthPanel with the providers it is given", () => {
230
- render(
231
- <SignInGate
232
- labels={GATE_LABELS}
233
- signInPath="/sign-in"
234
- providers={["google", "github"]}
235
- />,
236
- );
237
- expect(screen.getByTestId("sign-in-gate")).toBeInTheDocument();
238
- expect(screen.getByTestId("auth-panel-card")).toBeInTheDocument();
239
- expect(screen.getByTestId("auth-panel-provider-google")).toBeInTheDocument();
240
- expect(screen.getByTestId("auth-panel-provider-github")).toBeInTheDocument();
241
- });
242
-
243
- // #7419 — the browser has no provider env. Every provider env var is unset
244
- // here (the top-level beforeEach), exactly as in a browser bundle; the gate
245
- // must still render the providers its server-rendered parent resolved.
246
- it("renders the Google button from the prop with no provider env present (#7419)", () => {
247
- render(
248
- <SignInGate labels={GATE_LABELS} signInPath="/sign-in" providers={["google"]} />,
249
- );
250
- expect(screen.getByTestId("auth-panel-provider-google")).toBeInTheDocument();
251
- expect(screen.queryByTestId("sign-in-gate-empty")).not.toBeInTheDocument();
252
- });
253
-
254
- it("starts a Google social sign-in back to the current page on click", () => {
255
- render(
256
- <SignInGate labels={GATE_LABELS} signInPath="/sign-in" providers={["google"]} />,
257
- );
258
- screen.getByTestId("auth-panel-provider-google").click();
259
- expect(mockSignInSocial).toHaveBeenCalledWith({
260
- provider: "google",
261
- callbackURL: "/en/waitlist",
262
- });
263
- });
264
-
265
- it("renders an EmptyState when no provider is active", () => {
266
- render(<SignInGate labels={GATE_LABELS} signInPath="/sign-in" providers={[]} />);
267
- expect(screen.getByTestId("sign-in-gate-empty")).toBeInTheDocument();
268
- expect(screen.getByText("No providers")).toBeInTheDocument();
269
- expect(screen.queryByTestId("auth-panel-card")).not.toBeInTheDocument();
270
- });
271
-
272
- // ── #4984 — the link to apps/web's own /sign-in page ──────────────────────
273
-
274
- it("links to /sign-in?next=<pathname> under the AuthPanel", () => {
275
- render(
276
- <SignInGate labels={GATE_LABELS} signInPath="/sign-in" providers={["google"]} />,
277
- );
278
- const link = screen.getByTestId("sign-in-gate-link");
279
- expect(link).toHaveAttribute("href", "/sign-in?next=%2Fen%2Fwaitlist");
280
- expect(link).toHaveTextContent("Go to the sign-in page");
281
- expect(screen.getByTestId("auth-panel-card")).toBeInTheDocument();
282
- });
283
-
284
- it("links to /sign-in?next=<pathname> in the zero-provider branch too", () => {
285
- render(<SignInGate labels={GATE_LABELS} signInPath="/sign-in" providers={[]} />);
286
- expect(screen.getByTestId("sign-in-gate-empty")).toBeInTheDocument();
287
- expect(screen.getByTestId("sign-in-gate-link")).toHaveAttribute(
288
- "href",
289
- "/sign-in?next=%2Fen%2Fwaitlist",
290
- );
291
- });
292
-
293
- it("encodes the current pathname — /account round-trips as ?next=%2Faccount", () => {
294
- mockUsePathname.mockReturnValue("/account");
295
- render(
296
- <SignInGate labels={GATE_LABELS} signInPath="/sign-in" providers={["google"]} />,
297
- );
298
- expect(screen.getByTestId("sign-in-gate-link")).toHaveAttribute(
299
- "href",
300
- "/sign-in?next=%2Faccount",
146
+ configureGoogle();
147
+ mockRequestPathname = "/waitlist";
148
+ await expect(signedOutLayout()).rejects.toThrow(
149
+ "NEXT_REDIRECT /sign-in?next=%2Fwaitlist",
301
150
  );
302
151
  });
303
152
  });
304
153
 
305
- // #7419 AC-3 — a "use client" module is bundled for the browser, where
306
- // server-only env reads silently come back empty. The gate must not reach for
307
- // provider env at all; its parent RSC resolves the providers and passes them.
308
- describe("sign-in-gate.tsx — no server env read in a client component (#7419)", () => {
309
- const source = readFileSync(join(__dirname, "..", "sign-in-gate.tsx"), "utf8");
310
-
311
- it("is a client component", () => {
312
- expect(source.startsWith('"use client"')).toBe(true);
313
- });
314
-
315
- it("does not import lib/auth-env", () => {
316
- expect(source).not.toMatch(/from\s+["'][^"']*lib\/auth-env["']/);
317
- expect(source).not.toMatch(/require\(\s*["'][^"']*lib\/auth-env["']\s*\)/);
318
- });
319
-
320
- it("does not read process.env", () => {
321
- expect(source).not.toMatch(/process\.env/);
322
- });
323
- });
324
-
325
- // ── #7435 — the email sign-in link on the gate (AC-5, AC-4) ─────────────────
326
-
327
- function configureEmailLink(): void {
328
- process.env.AUTH_EMAIL_WEBHOOK_SECRET = "webhook-secret";
329
- process.env.AUTH_EMAIL_FROM = "noreply@example.test";
330
- process.env.BETTER_AUTH_URL = "https://site.example";
331
- process.env.BETTER_AUTH_SECRET = "a-real-secret";
332
- }
333
-
334
- async function renderSignedOutLayout(): Promise<void> {
335
- mockGetSession.mockResolvedValue(null);
336
- const element = await AuthedLayout({
337
- params: Promise.resolve({ locale: "en" }),
338
- children: <div data-testid="dashboard-content" />,
154
+ describe("AuthedLayout — a signed-out request redirects to /sign-in (#11095 AC-4)", () => {
155
+ it.each([
156
+ ["/account/billing", "en", "/sign-in?next=%2Faccount%2Fbilling"],
157
+ ["/account", "en", "/sign-in?next=%2Faccount"],
158
+ ["/waitlist", "en", "/sign-in?next=%2Fwaitlist"],
159
+ ["/fr/account", "fr", "/fr/sign-in?next=%2Ffr%2Faccount"],
160
+ ])("%s (locale %s) → %s", async (pathname, locale, target) => {
161
+ configureGoogle();
162
+ mockRequestPathname = pathname;
163
+ await expect(signedOutLayout(locale)).rejects.toThrow(
164
+ `NEXT_REDIRECT ${target}`,
165
+ );
339
166
  });
340
- render(element);
341
- }
342
167
 
343
- describe("AuthedLayout — the email sign-in link (#7435)", () => {
344
- beforeEach(() => {
345
- mockGetSession.mockReset();
346
- mockUsePathname.mockReset().mockReturnValue("/en/waitlist");
168
+ it("redirects to the bare /sign-in when there is no x-pathname", async () => {
169
+ configureGoogle();
170
+ await expect(signedOutLayout()).rejects.toThrow(/^NEXT_REDIRECT \/sign-in$/);
347
171
  });
348
172
 
349
- it("offers Google and 'Email me a sign-in link', with no AuthPanel password form", async () => {
350
- configureGoogle();
173
+ it("redirects when the email sign-in link is the only method", async () => {
351
174
  configureEmailLink();
352
- await renderSignedOutLayout();
353
- expect(screen.getByTestId("sign-in-gate")).toBeInTheDocument();
354
- // #8790 D4/D5: one card — Google is a social button under the "or", and the
355
- // sign-in link is the card's primary action.
356
- expect(screen.getByTestId("auth-social-google")).toBeInTheDocument();
357
- expect(screen.getByTestId("auth-submit")).toHaveTextContent(
358
- "copy:emailLinkSubmit",
359
- );
360
- expect(screen.queryByTestId("auth-panel-password")).not.toBeInTheDocument();
361
- expect(screen.queryByTestId("auth-panel-card")).not.toBeInTheDocument();
362
- expect(screen.getByTestId("sign-in-gate-link")).toHaveAttribute(
363
- "href",
364
- "/sign-in?next=%2Fen%2Fwaitlist",
175
+ mockRequestPathname = "/account";
176
+ await expect(signedOutLayout()).rejects.toThrow(
177
+ "NEXT_REDIRECT /sign-in?next=%2Faccount",
365
178
  );
366
179
  });
367
180
 
368
- it("renders the email-link form, not the EmptyState, when it is the only method", async () => {
369
- configureEmailLink();
370
- await renderSignedOutLayout();
371
- expect(screen.getByTestId("auth-email")).toBeInTheDocument();
372
- expect(screen.getByTestId("auth-submit")).toBeInTheDocument();
373
- expect(screen.queryByTestId("sign-in-gate-empty")).not.toBeInTheDocument();
374
- expect(screen.getByTestId("sign-in-gate-link")).toBeInTheDocument();
181
+ it("redirects an operator path even with no sign-in method on", async () => {
182
+ mockRequestPathname = "/waitlist";
183
+ await expect(signedOutLayout()).rejects.toThrow(
184
+ "NEXT_REDIRECT /sign-in?next=%2Fwaitlist",
185
+ );
375
186
  });
376
187
 
377
- it.each([
378
- "AUTH_EMAIL_WEBHOOK_SECRET",
379
- "AUTH_EMAIL_FROM",
380
- "BETTER_AUTH_URL",
381
- "BETTER_AUTH_SECRET",
382
- ])("renders no email-link form when %s is unset (AC-4)", async (name) => {
383
- configureGoogle();
384
- configureEmailLink();
385
- delete process.env[name];
386
- await renderSignedOutLayout();
387
- expect(screen.queryByTestId("auth-email")).not.toBeInTheDocument();
388
- expect(screen.getByTestId("auth-panel-provider-google")).toBeInTheDocument();
188
+ it("ships no (authed)/sign-in-gate.tsx and no account.gate.signInLink", () => {
189
+ expect(existsSync(join(__dirname, "..", "sign-in-gate.tsx"))).toBe(false);
190
+ expect("signInLink" in en.account.gate).toBe(false);
389
191
  });
390
192
  });
391
193
 
392
- // ── #7430 — the account area's gate speaks to members ──────────────────────
194
+ // ── #7430 — the account area's no-method block speaks to members ──────────
393
195
 
394
196
  function gateNamespaces(): unknown[] {
395
197
  return jest
@@ -397,97 +199,27 @@ function gateNamespaces(): unknown[] {
397
199
  .mock.calls.map((call) => (call[0] as { namespace?: string }).namespace);
398
200
  }
399
201
 
400
- describe("AuthedLayout — the signed-out gate on an account path (#7430)", () => {
401
- beforeEach(() => {
402
- mockGetSession.mockReset();
403
- jest.mocked(getTranslations).mockClear();
404
- mockUsePathname.mockReset().mockReturnValue("/account");
202
+ describe("AuthedLayout — an account path with no sign-in method on (#7430)", () => {
203
+ it("renders the not-configured block in place, with a real heading and one way home", async () => {
405
204
  mockRequestPathname = "/account";
406
- });
407
-
408
- it("reads the member-facing account.gate copy, never waitlistDashboard.gate", async () => {
409
- configureGoogle();
410
- await renderSignedOutLayout();
205
+ render(await signedOutLayout());
411
206
  expect(gateNamespaces()).toContain("account.gate");
412
207
  expect(gateNamespaces()).not.toContain("waitlistDashboard.gate");
413
- expect(screen.getByTestId("auth-sso-google")).toBeInTheDocument();
414
- expect(screen.getByTestId("sign-in-gate-link")).toHaveAttribute(
415
- "href",
416
- "/sign-in?next=%2Faccount",
417
- );
418
- });
419
-
420
- // A client component's props cross the RSC boundary: React refuses a
421
- // function there, so the card's copy must arrive as plain data (#9662 —
422
- // the 500 a function-valued `backTo` once caused here).
423
- it.each([
424
- ["Google", false],
425
- ["Google + the email link", true],
426
- ] as const)("hands SignInGate no function in its card props (%s)", async (_name, withEmailLink) => {
427
- configureGoogle();
428
- if (withEmailLink) configureEmailLink();
429
- mockGetSession.mockResolvedValue(null);
430
- const element = (await AuthedLayout({
431
- params: Promise.resolve({ locale: "en" }),
432
- children: <div />,
433
- })) as React.ReactElement<{ card?: { text: Record<string, unknown> } }>;
434
- const text = element.props.card?.text;
435
- expect(text).toBeDefined();
436
- const functions = Object.entries(text ?? {}).filter(
437
- ([, value]) => typeof value === "function",
438
- );
439
- expect(functions).toEqual([]);
440
- });
441
-
442
- it.each([
443
- ["Google", false],
444
- ["Google + the email link", true],
445
- ] as const)("renders the one card with %s: the mark, the toggle line and the acknowledgement (#9662)", async (_name, withEmailLink) => {
446
- configureGoogle();
447
- if (withEmailLink) configureEmailLink();
448
- await renderSignedOutLayout();
449
- expect(screen.getByTestId("sign-in-page")).toBeInTheDocument();
450
- expect(screen.queryByTestId("auth-panel-card")).not.toBeInTheDocument();
451
- expect(screen.getByTestId("auth-card-logo")).toBeInTheDocument();
452
- expect(screen.getByTestId("auth-card-prospect-link")).toHaveAttribute(
453
- "href",
454
- "/sign-up",
455
- );
456
- const footnote = screen.getByTestId("auth-card-footnote");
457
- expect(footnote.querySelector('a[href="/terms"]')).not.toBeNull();
458
- expect(footnote.querySelector('a[href="/privacy"]')).not.toBeNull();
459
- if (withEmailLink) {
460
- expect(screen.getByTestId("auth-submit")).toHaveTextContent(
461
- "copy:emailLinkSubmit",
462
- );
463
- expect(screen.getByTestId("auth-social-google")).toBeInTheDocument();
464
- } else {
465
- expect(screen.queryByTestId("auth-email")).not.toBeInTheDocument();
466
- }
467
- });
468
-
469
- it("renders the not-configured headline as a real heading, not a <p>", async () => {
470
- await renderSignedOutLayout();
471
- expect(gateNamespaces()).toContain("account.gate");
472
208
  expect(screen.getByTestId("account-sign-in-gate")).toBeInTheDocument();
473
- expect(screen.queryByTestId("sign-in-gate-empty")).not.toBeInTheDocument();
474
209
  expect(
475
210
  screen.getByRole("heading", { level: 1, name: "copy:emptyHeadline" }),
476
211
  ).toBeInTheDocument();
477
212
  expect(screen.getByText("copy:emptyDescription")).toBeInTheDocument();
478
- // With no sign-in method on, /sign-in is a dead end that shows operator
479
- // copy — the gate's one action goes back to the site instead.
480
- expect(screen.queryByTestId("sign-in-gate-link")).not.toBeInTheDocument();
481
213
  const home = screen.getByTestId("account-sign-in-gate-home");
482
214
  expect(home).toHaveAttribute("href", "/");
483
215
  expect(home).toHaveTextContent("copy:homeLink");
216
+ expect(document.querySelector('[data-testid^="sign-in-gate"]')).toBeNull();
484
217
  expect(screen.queryByTestId("dashboard-content")).not.toBeInTheDocument();
485
218
  });
486
219
 
487
- it("reads account.gate under a locale prefix and nested account paths too", async () => {
220
+ it("holds under a locale prefix and on nested account paths too", async () => {
488
221
  mockRequestPathname = "/en/account/settings";
489
- await renderSignedOutLayout();
490
- expect(gateNamespaces()).toContain("account.gate");
222
+ render(await signedOutLayout());
491
223
  expect(screen.getByRole("heading", { level: 1 })).toBeInTheDocument();
492
224
  expect(screen.getByTestId("account-sign-in-gate-home")).toHaveAttribute(
493
225
  "href",
@@ -495,13 +227,12 @@ describe("AuthedLayout — the signed-out gate on an account path (#7430)", () =
495
227
  );
496
228
  });
497
229
 
498
- it("keeps waitlistDashboard.gate on an operator path", async () => {
499
- mockRequestPathname = "/waitlist";
500
- await renderSignedOutLayout();
501
- expect(gateNamespaces()).toContain("waitlistDashboard.gate");
502
- expect(gateNamespaces()).not.toContain("account.gate");
503
- expect(screen.getByTestId("sign-in-gate-empty")).toBeInTheDocument();
504
- expect(screen.queryByTestId("account-sign-in-gate")).not.toBeInTheDocument();
230
+ it("counts the password method as no member sign-in method, as before", async () => {
231
+ process.env.AUTH_EMAIL_SERVER = "smtp://mail.example.test";
232
+ process.env.AUTH_EMAIL_FROM = "noreply@example.test";
233
+ mockRequestPathname = "/account";
234
+ render(await signedOutLayout());
235
+ expect(screen.getByTestId("account-sign-in-gate")).toBeInTheDocument();
505
236
  });
506
237
 
507
238
  it("ships member copy — no operator language in en.json's account.gate", () => {
@@ -59,6 +59,7 @@ jest.mock("../../../../../auth", () => ({
59
59
 
60
60
  const mockSubscriptionMe = jest.fn();
61
61
  const mockPortalSession = jest.fn();
62
+ const mockMemberPurchases = jest.fn();
62
63
  jest.mock("@working-theory/api-client", () => ({
63
64
  __esModule: true,
64
65
  waitlistSignups: { me: jest.fn() },
@@ -68,7 +69,7 @@ jest.mock("@working-theory/api-client", () => ({
68
69
  portalSession: (...args: unknown[]) => mockPortalSession(...args),
69
70
  },
70
71
  leads: { submit: jest.fn() },
71
- member: {},
72
+ member: { purchases: (...args: unknown[]) => mockMemberPurchases(...args) },
72
73
  hubSignIn: { me: jest.fn() },
73
74
  visitorForwardHeaders: () => null,
74
75
  }));
@@ -338,3 +339,13 @@ describe("#8217 AC-1 — the single site's Manage billing (D10, D11)", () => {
338
339
  errorSpy.mockRestore();
339
340
  });
340
341
  });
342
+
343
+ // #11096 D9 — the Purchases list is a hub-sign-in spoke's; a hub's own Billing
344
+ // never reads it.
345
+ describe("#11096 — no Purchases list on a hub", () => {
346
+ it("never reads member.purchases and renders no Purchases section", async () => {
347
+ await renderPage();
348
+ expect(mockMemberPurchases).not.toHaveBeenCalled();
349
+ expect(screen.queryByTestId("account-billing-purchases")).not.toBeInTheDocument();
350
+ });
351
+ });
@@ -395,7 +395,7 @@ describe("#8431 AC-4 — Security on a hub-mode spoke", () => {
395
395
  expect(screen.getByTestId("account-security-log-out")).toBeInTheDocument();
396
396
  });
397
397
 
398
- it("Log out POSTs the spoke's sign-out endpoint, never Better Auth, and on a 204 lands on /account", async () => {
398
+ it("Log out POSTs the spoke's sign-out endpoint, never Better Auth, and on a 204 lands on the home (#11095 D4)", async () => {
399
399
  mockFetch.mockResolvedValue({ ok: true, status: 204 });
400
400
  await renderSecurity();
401
401
  await act(async () => {
@@ -407,7 +407,7 @@ describe("#8431 AC-4 — Security on a hub-mode spoke", () => {
407
407
  credentials: "same-origin",
408
408
  });
409
409
  expect(mockSignOut).not.toHaveBeenCalled();
410
- expect(mockPush).toHaveBeenCalledWith("/account");
410
+ expect(mockPush).toHaveBeenCalledWith("/");
411
411
  });
412
412
 
413
413
  it("a refused sign-out (403) navigates nowhere and shows the error", async () => {
@@ -530,3 +530,56 @@ describe("#8217 AC-1 — Billing on a hub-mode spoke reads the seam's spoke bill
530
530
  errorSpy.mockRestore();
531
531
  });
532
532
  });
533
+
534
+ // #11096 D9 (AC-4) — a buyer's account finds the purchase by the verified-email
535
+ // join: on a hub-sign-in spoke Billing lists `member.purchases` under the plan.
536
+ describe("#11096 AC-4 — Billing lists the member's purchases on a hub-sign-in spoke", () => {
537
+ const PURCHASE = {
538
+ id: "purchase_01920000-1109-7000-8000-000000000001",
539
+ offering: "Strategy Session",
540
+ amountMinor: 25000,
541
+ currency: "usd",
542
+ period: null,
543
+ purchasedAt: "2026-11-07T12:00:00.000Z",
544
+ };
545
+
546
+ async function renderBilling(): Promise<void> {
547
+ // The Billing route's own page, loaded with `import()` — see the AC-5 case above.
548
+ const { default: BillingPage } = await import("../billing/page");
549
+ render(await BillingPage({ params: Promise.resolve({ locale: "en" }) }));
550
+ }
551
+
552
+ it("one purchase renders one row with its offering, read with the Bearer credential", async () => {
553
+ mockMemberPurchases.mockResolvedValue({ ok: true, body: { items: [PURCHASE] } });
554
+ await renderBilling();
555
+ const rows = screen.getAllByTestId("account-billing-purchase");
556
+ expect(rows).toHaveLength(1);
557
+ expect(rows[0]).toHaveTextContent("Strategy Session");
558
+ expect(rows[0]).toHaveTextContent("$250");
559
+ expect(screen.getByTestId("account-billing-purchases")).toHaveTextContent("Purchases");
560
+ expect(mockMemberPurchases).toHaveBeenCalledWith({
561
+ headers: { authorization: `Bearer ${CREDENTIAL}` },
562
+ });
563
+ });
564
+
565
+ it.each([
566
+ ["an empty list", { ok: true, body: { items: [] } }],
567
+ ["an older hub's 404", { ok: false, status: 404, body: {} }],
568
+ ])("%s shows nothing", async (_label, answer) => {
569
+ mockMemberPurchases.mockResolvedValue(answer);
570
+ await renderBilling();
571
+ expect(screen.queryByTestId("account-billing-purchases")).not.toBeInTheDocument();
572
+ expect(screen.queryByTestId("account-billing-purchases-error")).not.toBeInTheDocument();
573
+ });
574
+
575
+ it("a failed read shows the error row, never an empty list", async () => {
576
+ const errorSpy = jest.spyOn(console, "error").mockImplementation(() => {});
577
+ mockMemberPurchases.mockResolvedValue({ ok: false, status: 502, body: {} });
578
+ await renderBilling();
579
+ expect(screen.getByTestId("account-billing-purchases-error")).toHaveTextContent(
580
+ "We couldn't load your purchases.",
581
+ );
582
+ expect(screen.queryByTestId("account-billing-purchase")).not.toBeInTheDocument();
583
+ errorSpy.mockRestore();
584
+ });
585
+ });