create-ailk 0.38.0 → 0.39.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 (135) hide show
  1. package/dist/add-route.js +1 -1
  2. package/dist/derive-architecture.js +3 -1
  3. package/dist/remove-module.js +18 -14
  4. package/dist/routes.d.ts +29 -2
  5. package/dist/routes.js +269 -23
  6. package/dist/site-manifest.js +6 -4
  7. package/dist/site-roster.d.ts +11 -3
  8. package/dist/site-roster.js +42 -22
  9. package/dist/surfaces.d.ts +11 -3
  10. package/dist/surfaces.js +69 -22
  11. package/dist/sync-routes.js +22 -5
  12. package/dist/template-record.js +3 -1
  13. package/dist/topology.d.ts +11 -0
  14. package/dist/topology.js +253 -3
  15. package/package.json +3 -3
  16. package/templates/apps/web/CLAUDE.md +26 -4
  17. package/templates/apps/web/__tests__/__mocks__/next-intl-server.ts +5 -1
  18. package/templates/apps/web/__tests__/__mocks__/next-intl.ts +5 -1
  19. package/templates/apps/web/__tests__/auth/seam.test.ts +34 -0
  20. package/templates/apps/web/account.config.tsx +2 -3
  21. package/templates/apps/web/app/[locale]/(authed)/account/connect/__tests__/page.test.tsx +1 -1
  22. package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +1 -1
  23. package/templates/apps/web/app/[locale]/(authed)/signed-out-gate.generated.tsx +1 -1
  24. package/templates/apps/web/app/[locale]/layout.tsx +1 -1
  25. package/templates/apps/web/auth.config.tsx +107 -0
  26. package/templates/apps/web/auth.ts +2 -1
  27. package/templates/apps/web/i18n/request.ts +9 -2
  28. package/templates/apps/web/jest.config.cjs +4 -0
  29. package/templates/apps/web/lib/__tests__/fixtures/site-topology.ts +3 -0
  30. package/templates/apps/web/lib/__tests__/server-api.test.ts +1 -1
  31. package/templates/apps/web/lib/server-api.ts +1 -1
  32. package/templates/apps/web/lib/topology.generated.ts +5 -0
  33. package/templates/apps/web/messages/en.json +0 -152
  34. package/templates/apps/web/middleware.ts +12 -25
  35. package/templates/apps/web/next.config.mjs +8 -0
  36. package/templates/apps/web/package.json +1 -0
  37. package/templates/apps/web/types/messages.d.ts +6 -1
  38. package/versions.json +49 -48
  39. package/templates/apps/web/app/[locale]/(auth)/__tests__/auth-pages.test.tsx +0 -322
  40. package/templates/apps/web/app/[locale]/(auth)/__tests__/password-reset.test.tsx +0 -554
  41. package/templates/apps/web/app/[locale]/(auth)/consent/__tests__/consent-actions.test.ts +0 -56
  42. package/templates/apps/web/app/[locale]/(auth)/consent/__tests__/page.test.tsx +0 -164
  43. package/templates/apps/web/app/[locale]/(auth)/consent/consent-form.tsx +0 -132
  44. package/templates/apps/web/app/[locale]/(auth)/consent/consent.actions.ts +0 -51
  45. package/templates/apps/web/app/[locale]/(auth)/consent/page.tsx +0 -144
  46. package/templates/apps/web/app/[locale]/(auth)/forgot-password/forgot-password-card.tsx +0 -101
  47. package/templates/apps/web/app/[locale]/(auth)/forgot-password/page.tsx +0 -111
  48. package/templates/apps/web/app/[locale]/(auth)/layout.tsx +0 -81
  49. package/templates/apps/web/app/[locale]/(auth)/legal-footnote.tsx +0 -35
  50. package/templates/apps/web/app/[locale]/(auth)/reset-password/__tests__/return.test.tsx +0 -179
  51. package/templates/apps/web/app/[locale]/(auth)/reset-password/page.tsx +0 -157
  52. package/templates/apps/web/app/[locale]/(auth)/reset-password/reset-password-card.tsx +0 -126
  53. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/next-path.test.ts +0 -54
  54. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/page.test.tsx +0 -628
  55. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/remembered-method.test.ts +0 -43
  56. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/sign-in-card.test.tsx +0 -266
  57. package/templates/apps/web/app/[locale]/(auth)/sign-in/next-path.ts +0 -20
  58. package/templates/apps/web/app/[locale]/(auth)/sign-in/page.tsx +0 -234
  59. package/templates/apps/web/app/[locale]/(auth)/sign-in/remembered-method.ts +0 -37
  60. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-card.tsx +0 -323
  61. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-text.ts +0 -93
  62. package/templates/apps/web/app/[locale]/(auth)/sign-up/__tests__/page.test.tsx +0 -301
  63. package/templates/apps/web/app/[locale]/(auth)/sign-up/__tests__/sign-up-card.test.tsx +0 -309
  64. package/templates/apps/web/app/[locale]/(auth)/sign-up/page.tsx +0 -201
  65. package/templates/apps/web/app/[locale]/(auth)/sign-up/sign-up-card.tsx +0 -366
  66. package/templates/apps/web/app/[locale]/(auth)/use-auth-card-flow.ts +0 -116
  67. package/templates/apps/web/app/[locale]/(auth)/verify-email/__tests__/actions.test.ts +0 -94
  68. package/templates/apps/web/app/[locale]/(auth)/verify-email/actions.ts +0 -77
  69. package/templates/apps/web/app/[locale]/(auth)/verify-email/page.tsx +0 -154
  70. package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +0 -3
  71. package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +0 -3
  72. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +0 -3
  73. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +0 -2
  74. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +0 -3
  75. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +0 -12
  76. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +0 -12
  77. package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +0 -12
  78. package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/route.ts +0 -2
  79. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +0 -12
  80. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +0 -3
  81. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +0 -10
  82. package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +0 -3
  83. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/page.tsx +0 -3
  84. package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +0 -12
  85. package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +0 -2
  86. package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +0 -3
  87. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +0 -3
  88. package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +0 -2
  89. package/templates/apps/web/app/[locale]/(authed)/account/support/page.tsx +0 -3
  90. package/templates/apps/web/app/api/auth/[...all]/route.ts +0 -16
  91. package/templates/apps/web/app/api/auth/hub/__tests__/continuation.test.ts +0 -143
  92. package/templates/apps/web/app/api/auth/hub/__tests__/entry-routes.test.ts +0 -749
  93. package/templates/apps/web/app/api/auth/hub/authorize/__tests__/route.test.ts +0 -964
  94. package/templates/apps/web/app/api/auth/hub/authorize/route.ts +0 -390
  95. package/templates/apps/web/app/api/auth/hub/continuation.ts +0 -127
  96. package/templates/apps/web/app/api/auth/hub/continue/[ref]/__tests__/route.test.ts +0 -188
  97. package/templates/apps/web/app/api/auth/hub/continue/[ref]/route.ts +0 -53
  98. package/templates/apps/web/app/api/auth/hub/email/route.ts +0 -111
  99. package/templates/apps/web/app/api/auth/hub/entry-shared.ts +0 -163
  100. package/templates/apps/web/app/api/auth/hub/password/__tests__/return.test.ts +0 -86
  101. package/templates/apps/web/app/api/auth/hub/password/__tests__/route.test.ts +0 -368
  102. package/templates/apps/web/app/api/auth/hub/password/return.ts +0 -86
  103. package/templates/apps/web/app/api/auth/hub/password/route.ts +0 -171
  104. package/templates/apps/web/app/api/auth/hub/purchase/route.ts +0 -230
  105. package/templates/apps/web/app/api/auth/hub/purchase-link/route.ts +0 -174
  106. package/templates/apps/web/app/api/auth/hub/sign-up/route.ts +0 -60
  107. package/templates/apps/web/app/api/auth/hub/sign-up-evidence.ts +0 -97
  108. package/templates/apps/web/app/api/auth/mcp/__tests__/continuation.test.ts +0 -92
  109. package/templates/apps/web/app/api/auth/mcp/continuation.ts +0 -89
  110. package/templates/apps/web/app/api/auth/mcp/continue/[ref]/__tests__/route.test.ts +0 -59
  111. package/templates/apps/web/app/api/auth/mcp/continue/[ref]/route.ts +0 -41
  112. package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +0 -1166
  113. package/templates/apps/web/app/api/hub-session/callback/route.ts +0 -134
  114. package/templates/apps/web/app/api/hub-session/email/route.ts +0 -125
  115. package/templates/apps/web/app/api/hub-session/one-tap/nonce/route.ts +0 -49
  116. package/templates/apps/web/app/api/hub-session/one-tap/route.ts +0 -106
  117. package/templates/apps/web/app/api/hub-session/open/route.ts +0 -111
  118. package/templates/apps/web/app/api/hub-session/password/return/route.ts +0 -69
  119. package/templates/apps/web/app/api/hub-session/password/route.ts +0 -106
  120. package/templates/apps/web/app/api/hub-session/sign-in/route.ts +0 -91
  121. package/templates/apps/web/app/api/hub-session/sign-out/route.ts +0 -54
  122. package/templates/apps/web/components/sign-out-trigger.tsx +0 -62
  123. package/templates/apps/web/lib/__tests__/auth-routes.test.ts +0 -140
  124. package/templates/apps/web/lib/auth-routes.ts +0 -125
  125. package/templates/apps/web/lib/hub-session/__tests__/hub-session.test.ts +0 -433
  126. package/templates/apps/web/lib/hub-session/__tests__/spoke-sign-in.test.tsx +0 -332
  127. package/templates/apps/web/lib/hub-session/config.ts +0 -110
  128. package/templates/apps/web/lib/hub-session/entry.ts +0 -238
  129. package/templates/apps/web/lib/hub-session/index.ts +0 -21
  130. package/templates/apps/web/lib/hub-session/one-tap.tsx +0 -148
  131. package/templates/apps/web/lib/hub-session/reseal.ts +0 -90
  132. package/templates/apps/web/lib/hub-session/seal.ts +0 -86
  133. package/templates/apps/web/lib/hub-session/session.ts +0 -298
  134. package/templates/apps/web/lib/hub-session/spoke-sign-in.tsx +0 -277
  135. package/templates/apps/web/lib/next-path.ts +0 -35
@@ -1,54 +0,0 @@
1
- /**
2
- * Tests for `resolveNextPath` — the /sign-in `?next=` sanitizer (#4984).
3
- * Foreign, protocol-relative, backslash, control-char, and non-string inputs
4
- * all fall back; plain in-app paths pass through unchanged.
5
- *
6
- * `hrefWithNext` (#9912 D4) — a toggle carries `?next=` only when the page's
7
- * resolved `next` is not its fallback.
8
- */
9
- import { hrefWithNext, resolveNextPath } from "../next-path";
10
-
11
- const FALLBACK = "/account";
12
-
13
- describe("resolveNextPath()", () => {
14
- it.each(["/account", "/en/account?tab=x", "/waitlist#a"])(
15
- "accepts the in-app path %p",
16
- (raw) => {
17
- expect(resolveNextPath(raw, FALLBACK)).toBe(raw);
18
- },
19
- );
20
-
21
- it.each([
22
- ["protocol-relative", "//evil.com"],
23
- ["backslash host trick", "/\\evil.com"],
24
- ["absolute URL", "https://evil.com"],
25
- ["bare host", "evil.com"],
26
- ["embedded space", "/acc ount"],
27
- ["CRLF", "/x\r\ny"],
28
- ["empty string", ""],
29
- ["undefined", undefined],
30
- ["string[] (repeated param)", ["/a"]],
31
- ])("rejects %s → fallback", (_label, raw) => {
32
- expect(resolveNextPath(raw, FALLBACK)).toBe(FALLBACK);
33
- });
34
- });
35
-
36
- describe("hrefWithNext()", () => {
37
- it("the fallback gives the bare href", () => {
38
- expect(hrefWithNext("/sign-up", "/account", "/account")).toBe("/sign-up");
39
- });
40
-
41
- it("any other next rides as ?next=, URL-encoded", () => {
42
- expect(
43
- hrefWithNext("/sign-up", "/api/auth/hub/continue/abc_-1", "/account"),
44
- ).toBe("/sign-up?next=%2Fapi%2Fauth%2Fhub%2Fcontinue%2Fabc_-1");
45
- expect(
46
- hrefWithNext("/fr/sign-in", "/fr/account?tab=x", "/fr/account"),
47
- ).toBe("/fr/sign-in?next=%2Ffr%2Faccount%3Ftab%3Dx");
48
- });
49
-
50
- it("a refused next resolves to the fallback, so its toggle is bare", () => {
51
- const next = resolveNextPath("//evil.example", FALLBACK);
52
- expect(hrefWithNext("/sign-up", next, FALLBACK)).toBe("/sign-up");
53
- });
54
- });
@@ -1,628 +0,0 @@
1
- /**
2
- * Tests for the `/[locale]/sign-in` page (#4984).
3
- *
4
- * Covers:
5
- * (a) OAuth-only (google) → sso body, exactly that provider, no email
6
- * field, no sign-up footer.
7
- * (b) google + github + email → password body with both social buttons,
8
- * still no sign-up footer.
9
- * (c) zero providers → inert card (no buttons, no form, not-configured
10
- * subhead) — never a fabricated session.
11
- * (d) provider click → `signIn.social({ provider, callbackURL: next })`;
12
- * a failed launch renders the providerFailed message.
13
- * (e) a foreign / protocol-relative `?next=` falls back to /account.
14
- * (f) password submit → `signIn.email` with the typed credentials; an
15
- * error result renders the signInFailed message.
16
- * (g) the "Forgot password?" link renders only when the reset predicate is
17
- * true — never a dead end pointing at reset's not-available state
18
- * (#6018 AC-1). (#6068 repointed that predicate from `isResetAvailable()`
19
- * to `resetSendConfigured()`; the mock below binds both to one fn, so
20
- * these cases read identically either way.)
21
- * (h) the email sign-in link (#7435): with "magic-link" active the form
22
- * renders beside the providers (or alone); a `?error=` from a failed
23
- * link maps to fixed copy and is never echoed.
24
- * (i) the hinted email (#8757 D9): a valid single `?email=` is the starting
25
- * value of every email input of the card; an invalid or repeated value,
26
- * or none, leaves them empty as before. It signs no one in.
27
- * (j) the one card (#9662): the site's logo and "Sign in to <site>" from
28
- * the deployment's own data — a crafted query parameter cannot change
29
- * the name — the "Don't have an account? Sign up" line linking
30
- * /sign-up, and the Terms + Privacy acknowledgement.
31
- * (k) the Sign up toggle (#9912 D4): it carries the validated `?next=` to
32
- * /sign-up; a `next` resolveNextPath refuses, or none, gives the bare
33
- * /sign-up.
34
- *
35
- * `next-intl/server` is mocked here against the real en.json, with `{name}`
36
- * placeholders filled from the values passed, so `signIn` copy is asserted
37
- * by its real strings and the heading by the name actually interpolated.
38
- */
39
- import { render, screen, within } from "@testing-library/react";
40
- import userEvent from "@testing-library/user-event";
41
-
42
- const mockGetActiveProviderIds = jest.fn();
43
- const mockIsResetAvailable = jest.fn();
44
- // eslint-disable-next-line no-restricted-syntax -- #507: mock-internal rewrite pending; auth-env.ts is a pure env-introspection module with no external boundary to mock instead.
45
- jest.mock("../../../../../lib/auth-env", () => ({
46
- __esModule: true,
47
- getActiveProviderIds: () => mockGetActiveProviderIds(),
48
- isResetAvailable: () => mockIsResetAvailable(),
49
- // #6068 repointed the forgot link from the flag-only `isResetAvailable()`
50
- // at the send conjunction. This is a PARTIAL module mock, so an absent
51
- // member is `undefined` rather than the real function — the page would
52
- // throw on EVERY render here, not only the two (g) cases. Bound to the SAME
53
- // jest.fn() the flag already drives, so every case below keeps the exact
54
- // truth value and the exact expectation it was written with: no assertion
55
- // in this file changes. Same remedy, same reason, as the sibling
56
- // `auth-pages.test.tsx` mock.
57
- resetSendConfigured: () => mockIsResetAvailable(),
58
- }));
59
-
60
- const mockSocial = jest.fn();
61
- const mockEmail = jest.fn();
62
- jest.mock("better-auth/react", () => ({
63
- __esModule: true,
64
- createAuthClient: () => ({
65
- signIn: {
66
- social: (...args: unknown[]) => mockSocial(...args),
67
- email: (...args: unknown[]) => mockEmail(...args),
68
- },
69
- }),
70
- }));
71
-
72
- // #8790 D2 — the spoke back link. The hub's secret and the registry read are
73
- // the two boundaries the page crosses; the continuation itself is REAL
74
- // (minted below with the same test secret), so the sealed-ref path is covered.
75
- const TEST_SECRET = "test-secret-for-the-sign-in-page-suite";
76
- // eslint-disable-next-line no-restricted-syntax -- #507: mock-internal rewrite pending; auth.ts is Better Auth's server singleton (a DB/HTTP boundary)
77
- jest.mock("../../../../../auth", () => ({
78
- __esModule: true,
79
- resolveSecret: () => TEST_SECRET,
80
- }));
81
- // #11095 D7 — the remembered-method cookie, read through `cookies()`.
82
- const mockCookies: Record<string, string> = {};
83
- jest.mock("next/headers", () => ({
84
- __esModule: true,
85
- cookies: async () => ({
86
- get: (name: string) =>
87
- name in mockCookies ? { name, value: mockCookies[name] } : undefined,
88
- }),
89
- }));
90
- const mockClientInfo = jest.fn();
91
- jest.mock("@working-theory/api-client", () => ({
92
- __esModule: true,
93
- hubSignIn: { clientInfo: (...args: unknown[]) => mockClientInfo(...args) },
94
- }));
95
- // The global shim (__tests__/__mocks__/next-intl-server.ts) returns messages
96
- // uninterpolated; this suite fills `{name}` placeholders so the heading's
97
- // organization name is the one the page actually passed (#9662).
98
- jest.mock("next-intl/server", () => {
99
- const messages = jest.requireActual("../../../../../messages/en.json") as Record<
100
- string,
101
- Record<string, string>
102
- >;
103
- return {
104
- __esModule: true,
105
- getTranslations: async ({ namespace }: { namespace: string }) => {
106
- const catalog = messages[namespace];
107
- const t = (key: string, values?: Record<string, string>): string =>
108
- (catalog?.[key] ?? `${namespace}.${key}`).replace(
109
- /\{(\w+)\}/g,
110
- (match, name: string) => values?.[name] ?? match,
111
- );
112
- t.has = (key: string): boolean => catalog?.[key] !== undefined;
113
- return t;
114
- },
115
- };
116
- });
117
-
118
- import { mintContinuation } from "../../../../api/auth/hub/continuation";
119
- import { SITE_NAME } from "../../../../../lib/site-brand";
120
- import en from "../../../../../messages/en.json";
121
- import Page, { generateMetadata } from "../page";
122
-
123
- async function renderPage(next?: string, error?: string): Promise<void> {
124
- const el = await Page({
125
- params: Promise.resolve({ locale: "en" }),
126
- searchParams: Promise.resolve({
127
- ...(next === undefined ? {} : { next }),
128
- ...(error === undefined ? {} : { error }),
129
- }),
130
- });
131
- render(el);
132
- }
133
-
134
- beforeEach(() => {
135
- for (const name of Object.keys(mockCookies)) delete mockCookies[name];
136
- mockGetActiveProviderIds.mockReset().mockReturnValue(["google"]);
137
- mockIsResetAvailable.mockReset().mockReturnValue(false);
138
- mockSocial.mockReset().mockResolvedValue({ data: {}, error: null });
139
- mockEmail.mockReset().mockResolvedValue({ data: {}, error: null });
140
- });
141
-
142
- describe("generateMetadata()", () => {
143
- it("uses the signIn namespace title + description", async () => {
144
- const meta = await generateMetadata({
145
- params: Promise.resolve({ locale: "en" }),
146
- searchParams: Promise.resolve({}),
147
- });
148
- expect(meta.title).toBe(en.signIn.title);
149
- expect(meta.description).toBe(en.signIn.description);
150
- });
151
- });
152
-
153
- describe("/sign-in page", () => {
154
- it("(a) OAuth-only: sso body with exactly the reported provider, no sign-up footer", async () => {
155
- await renderPage("/account");
156
- expect(screen.getByTestId("sign-in-page")).toBeInTheDocument();
157
- expect(screen.getByTestId("auth-card")).toBeInTheDocument();
158
- expect(screen.getByTestId("auth-sso-google")).toBeInTheDocument();
159
- expect(screen.queryByTestId("auth-sso-github")).toBeNull();
160
- expect(screen.queryByTestId("auth-email")).toBeNull();
161
- expect(screen.queryByTestId("auth-submit")).toBeNull();
162
- expect(screen.queryByTestId("auth-footer-link")).toBeNull();
163
- expect(screen.queryByText(/create an account/i)).toBeNull();
164
- expect(
165
- screen.getByRole("heading", { name: `Sign in to ${SITE_NAME}` }),
166
- ).toBeInTheDocument();
167
- });
168
-
169
- it("(b) email + OAuth: password body with both social buttons, no sign-up footer", async () => {
170
- mockGetActiveProviderIds.mockReturnValue(["google", "github", "email"]);
171
- await renderPage("/account");
172
- expect(screen.getByTestId("auth-email")).toBeInTheDocument();
173
- expect(screen.getByTestId("auth-password")).toBeInTheDocument();
174
- expect(screen.getByTestId("auth-social-row")).toBeInTheDocument();
175
- expect(screen.getByTestId("auth-social-google")).toBeInTheDocument();
176
- expect(screen.getByTestId("auth-social-github")).toBeInTheDocument();
177
- expect(screen.queryByTestId("auth-sso-stack")).toBeNull();
178
- expect(screen.queryByTestId("auth-footer-link")).toBeNull();
179
- });
180
-
181
- it("(c) zero providers: inert card with the not-configured subhead, no buttons, no form", async () => {
182
- mockGetActiveProviderIds.mockReturnValue([]);
183
- await renderPage();
184
- expect(screen.getByTestId("auth-card")).toBeInTheDocument();
185
- expect(screen.queryByTestId("auth-sso-google")).toBeNull();
186
- expect(screen.queryByTestId("auth-sso-github")).toBeNull();
187
- expect(screen.queryByTestId("auth-submit")).toBeNull();
188
- expect(screen.queryByTestId("auth-email")).toBeNull();
189
- expect(
190
- screen.getByText(en.signIn.notConfiguredSubhead),
191
- ).toBeInTheDocument();
192
- expect(mockSocial).not.toHaveBeenCalled();
193
- });
194
-
195
- it("(d) provider click launches signIn.social with the sanitised next path", async () => {
196
- const user = userEvent.setup();
197
- await renderPage("/account");
198
- await user.click(screen.getByTestId("auth-sso-google"));
199
- expect(mockSocial).toHaveBeenCalledTimes(1);
200
- expect(mockSocial).toHaveBeenCalledWith({
201
- provider: "google",
202
- callbackURL: "/account",
203
- });
204
- });
205
-
206
- it("(d) a failed provider launch renders the providerFailed message", async () => {
207
- const user = userEvent.setup();
208
- mockSocial.mockResolvedValue({ data: null, error: { message: "nope" } });
209
- await renderPage("/account");
210
- await user.click(screen.getByTestId("auth-sso-google"));
211
- expect(
212
- await screen.findByText(en.signIn.providerFailed),
213
- ).toBeInTheDocument();
214
- });
215
-
216
- it("(e) a protocol-relative ?next= falls back to /account", async () => {
217
- const user = userEvent.setup();
218
- await renderPage("//evil.com");
219
- await user.click(screen.getByTestId("auth-sso-google"));
220
- expect(mockSocial).toHaveBeenCalledWith({
221
- provider: "google",
222
- callbackURL: "/account",
223
- });
224
- });
225
-
226
- it("(f) password submit calls signIn.email and surfaces signInFailed on error", async () => {
227
- const user = userEvent.setup();
228
- mockGetActiveProviderIds.mockReturnValue(["google", "email"]);
229
- mockEmail.mockResolvedValue({ data: null, error: { message: "bad" } });
230
- await renderPage("/en/account?tab=x");
231
- await user.type(screen.getByTestId("auth-email"), "ada@example.com");
232
- await user.type(screen.getByTestId("auth-password"), "s3cr3t");
233
- await user.click(screen.getByTestId("auth-submit"));
234
- expect(mockEmail).toHaveBeenCalledWith({
235
- email: "ada@example.com",
236
- password: "s3cr3t",
237
- callbackURL: "/en/account?tab=x",
238
- });
239
- expect(await screen.findByText(en.signIn.signInFailed)).toBeInTheDocument();
240
- });
241
-
242
- it("(f) a rejected signIn.email call surfaces signInFailed too (code review, #6018)", async () => {
243
- const user = userEvent.setup();
244
- mockGetActiveProviderIds.mockReturnValue(["google", "email"]);
245
- mockEmail.mockRejectedValue(new Error("network"));
246
- await renderPage("/account");
247
- await user.type(screen.getByTestId("auth-email"), "ada@example.com");
248
- await user.type(screen.getByTestId("auth-password"), "s3cr3t");
249
- await user.click(screen.getByTestId("auth-submit"));
250
- expect(await screen.findByText(en.signIn.signInFailed)).toBeInTheDocument();
251
- });
252
-
253
- it("(g) renders the forgot link when password reset is available", async () => {
254
- mockGetActiveProviderIds.mockReturnValue(["google", "email"]);
255
- mockIsResetAvailable.mockReturnValue(true);
256
- await renderPage("/account");
257
- expect(screen.getByTestId("auth-forgot")).toHaveAttribute(
258
- "href",
259
- "/forgot-password",
260
- );
261
- });
262
-
263
- it("(g) omits the forgot link when password reset is unavailable", async () => {
264
- mockGetActiveProviderIds.mockReturnValue(["google", "email"]);
265
- mockIsResetAvailable.mockReturnValue(false);
266
- await renderPage("/account");
267
- expect(screen.getByTestId("auth-password")).toBeInTheDocument();
268
- expect(screen.queryByTestId("auth-forgot")).toBeNull();
269
- });
270
- });
271
-
272
- describe("/sign-in page — the email sign-in link (#7435)", () => {
273
- it("(h) renders no email-link form when 'magic-link' is not active", async () => {
274
- mockGetActiveProviderIds.mockReturnValue(["google", "email"]);
275
- await renderPage("/account");
276
- expect(screen.queryByTestId("auth-email-link-form")).toBeNull();
277
- });
278
-
279
- it("(h) with google + magic-link: the Google button and 'Email me a sign-in link'", async () => {
280
- mockGetActiveProviderIds.mockReturnValue(["google", "magic-link"]);
281
- await renderPage("/account");
282
- // Google sits under the "or" as a social button, no longer an SSO stack.
283
- expect(screen.getByTestId("auth-social-google")).toBeInTheDocument();
284
- expect(screen.queryByTestId("auth-sso-google")).toBeNull();
285
- expect(screen.getByTestId("auth-submit")).toHaveTextContent(
286
- en.signIn.emailLinkSubmit,
287
- );
288
- expect(en.signIn.emailLinkSubmit).toBe("Send me a magic link");
289
- // One "or" divider between the primary and Google (#8790 D5).
290
- expect(screen.getAllByTestId("auth-divider")).toHaveLength(1);
291
- expect(screen.queryByTestId("auth-email-link-divider")).toBeNull();
292
- });
293
-
294
- it("(h) with magic-link only: the form renders and the not-configured subhead does not", async () => {
295
- mockGetActiveProviderIds.mockReturnValue(["magic-link"]);
296
- await renderPage();
297
- expect(screen.getByTestId("auth-email")).toBeInTheDocument();
298
- expect(screen.queryByText(en.signIn.notConfiguredSubhead)).toBeNull();
299
- // The heading stands alone — no subhead (#8790 D3); #9662 names the site.
300
- expect(
301
- screen.getByRole("heading", { name: `Sign in to ${SITE_NAME}` }),
302
- ).toBeInTheDocument();
303
- expect(en.signIn.heading).toBe("Sign in to {site}");
304
- expect(screen.queryByTestId("auth-method-switch")).toBeNull();
305
- });
306
-
307
- it("(h) beside the password form when the password method is active too", async () => {
308
- mockGetActiveProviderIds.mockReturnValue(["google", "email", "magic-link"]);
309
- await renderPage("/account");
310
- // The sign-in link leads; the password is one quiet switch away, in place
311
- // (#8790 D4), and the typed email survives the switch.
312
- expect(screen.queryByTestId("auth-password")).toBeNull();
313
- expect(screen.getByTestId("auth-submit")).toHaveTextContent(
314
- en.signIn.emailLinkSubmit,
315
- );
316
- const user = userEvent.setup();
317
- await user.type(screen.getByTestId("auth-email"), "member@example.com");
318
- await user.click(screen.getByTestId("auth-method-switch"));
319
- expect(screen.getByTestId("auth-password")).toBeInTheDocument();
320
- expect(screen.getByTestId("auth-email")).toHaveValue("member@example.com");
321
- expect(screen.getByTestId("auth-submit")).toHaveTextContent(
322
- en.signIn.submit,
323
- );
324
- expect(screen.getByTestId("auth-method-switch")).toHaveTextContent(
325
- en.signIn.useEmailLink,
326
- );
327
- });
328
-
329
- it.each(["INVALID_TOKEN", "new_user_signup_disabled"])(
330
- "(h) ?error=%s renders the expired-link notice",
331
- async (error) => {
332
- mockGetActiveProviderIds.mockReturnValue(["google", "magic-link"]);
333
- await renderPage("/account", error);
334
- expect(screen.getByTestId("sign-in-link-notice")).toHaveTextContent(
335
- en.signIn.emailLinkExpired,
336
- );
337
- },
338
- );
339
-
340
- it("(h) any other ?error renders signInFailed and never echoes the value", async () => {
341
- mockGetActiveProviderIds.mockReturnValue(["google", "magic-link"]);
342
- await renderPage("/account", "<script>alert(1)</script>");
343
- expect(screen.getByTestId("sign-in-link-notice")).toHaveTextContent(
344
- en.signIn.signInFailed,
345
- );
346
- expect(document.body.innerHTML).not.toContain("alert(1)");
347
- expect(document.body.innerHTML).not.toContain("&lt;script");
348
- });
349
-
350
- it("(h) no ?error → no notice", async () => {
351
- mockGetActiveProviderIds.mockReturnValue(["google", "magic-link"]);
352
- await renderPage("/account");
353
- expect(screen.queryByTestId("sign-in-link-notice")).toBeNull();
354
- });
355
- });
356
-
357
- describe("/sign-in page — the spoke back link (#8790 D2)", () => {
358
- beforeEach(() => {
359
- mockClientInfo.mockReset();
360
- });
361
-
362
- it("names the spoke from the registry when the continuation opens", async () => {
363
- mockClientInfo.mockResolvedValue({
364
- ok: true,
365
- body: {
366
- clientId: "spoke_1",
367
- name: "Wendi Henry",
368
- origin: "https://wendihenry.com",
369
- },
370
- });
371
- const ref = mintContinuation(
372
- "client_id=spoke_1&response_type=code",
373
- TEST_SECRET,
374
- );
375
- await renderPage(`/api/auth/hub/continue/${ref}`);
376
- expect(mockClientInfo).toHaveBeenCalledWith("spoke_1");
377
- const back = screen.getByTestId("auth-back-link");
378
- // #11095 D5: the spoke's home — its /account would start the hub hop again.
379
- expect(back).toHaveAttribute("href", "https://wendihenry.com/");
380
- // This suite's next-intl shim returns messages uninterpolated, so the
381
- // label's shape is what is asserted here; the ICU fill is next-intl's.
382
- expect(back).toHaveTextContent(/^Back to/);
383
- });
384
-
385
- it("renders no back link when the registry does not know the client", async () => {
386
- mockClientInfo.mockResolvedValue({ ok: false, status: 404 });
387
- const ref = mintContinuation("client_id=spoke_gone", TEST_SECRET);
388
- await renderPage(`/api/auth/hub/continue/${ref}`);
389
- expect(screen.queryByTestId("auth-back-link")).toBeNull();
390
- });
391
-
392
- it("renders no back link on a direct visit", async () => {
393
- await renderPage("/account");
394
- expect(screen.queryByTestId("auth-back-link")).toBeNull();
395
- });
396
-
397
- it("renders no back link, and no error, when the continuation cannot be opened", async () => {
398
- // A continuation-shaped `next` whose ref is garbage: the secret load or
399
- // the open throws, and the page degrades to the direct-visit render.
400
- mockGetActiveProviderIds.mockReturnValue(["google", "magic-link"]);
401
- await renderPage("/api/auth/hub/continue/not-a-real-continuation");
402
- expect(screen.queryByTestId("auth-back-link")).toBeNull();
403
- expect(screen.getByTestId("auth-email")).toBeInTheDocument();
404
- });
405
- });
406
-
407
- describe("/sign-in page — the hinted email (#8757 D9)", () => {
408
- async function renderWithEmail(email?: string | string[]): Promise<void> {
409
- const el = await Page({
410
- params: Promise.resolve({ locale: "en" }),
411
- searchParams: Promise.resolve({
412
- next: "/account",
413
- ...(email === undefined ? {} : { email }),
414
- }),
415
- });
416
- render(el);
417
- }
418
-
419
- function emailInputs(): HTMLInputElement[] {
420
- return Array.from(
421
- document.querySelectorAll<HTMLInputElement>('input[type="email"]'),
422
- );
423
- }
424
-
425
- beforeEach(() => {
426
- // One email input on the card (#8790 D4): the sign-in link and the password share it.
427
- mockGetActiveProviderIds.mockReturnValue(["google", "email", "magic-link"]);
428
- });
429
-
430
- it("(i) ?email=a%40b.example → the card's email input has that value", async () => {
431
- // Next hands the page the decoded value.
432
- await renderWithEmail("a@b.example");
433
- const inputs = emailInputs();
434
- expect(inputs).toHaveLength(1);
435
- expect(screen.getByTestId("auth-email")).toHaveValue("a@b.example");
436
- for (const input of inputs) expect(input).toHaveValue("a@b.example");
437
- // A starting value only — nothing was sent.
438
- expect(mockEmail).not.toHaveBeenCalled();
439
- expect(mockSocial).not.toHaveBeenCalled();
440
- });
441
-
442
- it.each([
443
- ["an invalid value (?email=nope)", "nope"],
444
- [
445
- "a repeated value (?email=a%40b.example&email=c%40d.example)",
446
- ["a@b.example", "c@d.example"],
447
- ],
448
- ["a value carrying a query separator", "a@b.example&next=/x"],
449
- ["no parameter", undefined],
450
- ] as const)(
451
- "(i) %s → empty email inputs, as today",
452
- async (_label, email) => {
453
- await renderWithEmail(
454
- email === undefined || typeof email === "string" ? email : [...email],
455
- );
456
- const inputs = emailInputs();
457
- expect(inputs).toHaveLength(1);
458
- for (const input of inputs) {
459
- expect(input).toHaveValue("");
460
- expect(input).not.toHaveAttribute("value");
461
- }
462
- },
463
- );
464
- });
465
-
466
- describe("/sign-in page — the one card (#9662)", () => {
467
- beforeEach(() => {
468
- mockGetActiveProviderIds.mockReturnValue(["google", "email", "magic-link"]);
469
- });
470
-
471
- it("(j) renders the site's logo and 'Sign in to <site>' from the deployment's data", async () => {
472
- await renderPage("/account");
473
- expect(screen.getByTestId("auth-card-logo")).toBeInTheDocument();
474
- expect(screen.getByRole("heading", { level: 2 })).toHaveTextContent(
475
- `Sign in to ${SITE_NAME}`,
476
- );
477
- expect(screen.getByLabelText(en.signIn.email)).toBe(
478
- screen.getByTestId("auth-email"),
479
- );
480
- expect(en.signIn.email).toBe("Email");
481
- });
482
-
483
- it("(j) a crafted query parameter cannot change the organization name", async () => {
484
- const crafted = "Evil Corp";
485
- expect(SITE_NAME).not.toBe(crafted);
486
- const el = await Page({
487
- params: Promise.resolve({ locale: "en" }),
488
- searchParams: Promise.resolve({
489
- next: `/account?site=${encodeURIComponent(crafted)}`,
490
- site: crafted,
491
- organization: crafted,
492
- name: crafted,
493
- siteName: crafted,
494
- }),
495
- });
496
- render(el);
497
- expect(screen.getByRole("heading", { level: 2 })).toHaveTextContent(
498
- `Sign in to ${SITE_NAME}`,
499
- );
500
- expect(document.body.textContent).not.toContain(crafted);
501
- });
502
-
503
- it("(j) the prospect line toggles to /sign-up, with no trailing period", async () => {
504
- await renderPage("/account");
505
- expect(screen.getByTestId("auth-card-prospect")).toHaveTextContent(
506
- /^Don't have an account\? Sign up$/,
507
- );
508
- expect(screen.getByTestId("auth-card-prospect-link")).toHaveAttribute(
509
- "href",
510
- "/sign-up",
511
- );
512
- });
513
-
514
- it("(j) 'Send me a magic link' first, the in-place password switch, then 'or' and Google", async () => {
515
- await renderPage("/account");
516
- expect(screen.getByTestId("auth-submit")).toHaveTextContent(
517
- "Send me a magic link",
518
- );
519
- expect(screen.getByTestId("auth-method-switch")).toHaveTextContent(
520
- "Sign in using password",
521
- );
522
- expect(screen.getByTestId("auth-divider")).toHaveTextContent(/^or$/);
523
- expect(screen.getByTestId("auth-social-google")).toBeInTheDocument();
524
- });
525
-
526
- it("(j) ends on the Terms of Service + Privacy Policy acknowledgement, linking the site's own routes", async () => {
527
- await renderPage("/account");
528
- const footnote = screen.getByTestId("auth-card-footnote");
529
- expect(footnote).toHaveTextContent(
530
- /^You acknowledge that you read, and agree to our Terms of Service and our Privacy Policy\.$/,
531
- );
532
- expect(
533
- within(footnote).getByRole("link", { name: "Terms of Service" }),
534
- ).toHaveAttribute("href", "/terms");
535
- expect(
536
- within(footnote).getByRole("link", { name: "Privacy Policy" }),
537
- ).toHaveAttribute("href", "/privacy");
538
- expect(within(footnote).getAllByRole("link")).toHaveLength(2);
539
- });
540
- });
541
-
542
- describe("/sign-in page — the Sign up toggle keeps the next (#9912 D4)", () => {
543
- beforeEach(() => {
544
- mockClientInfo.mockReset().mockResolvedValue({ ok: false, status: 404 });
545
- });
546
-
547
- it("(k) a continuation next rides the toggle to /sign-up, URL-encoded", async () => {
548
- const ref = mintContinuation("client_id=spoke_1", TEST_SECRET);
549
- const next = `/api/auth/hub/continue/${ref}`;
550
- await renderPage(next);
551
- expect(screen.getByTestId("auth-card-prospect-link")).toHaveAttribute(
552
- "href",
553
- `/sign-up?next=${encodeURIComponent(next)}`,
554
- );
555
- });
556
-
557
- it("(k) an in-app next rides the toggle too", async () => {
558
- await renderPage("/account/billing");
559
- expect(screen.getByTestId("auth-card-prospect-link")).toHaveAttribute(
560
- "href",
561
- "/sign-up?next=%2Faccount%2Fbilling",
562
- );
563
- });
564
-
565
- it.each([
566
- ["a protocol-relative next", "//evil.example"],
567
- ["an absolute next", "https://evil.example/x"],
568
- ["a backslash next", "/\\evil.example"],
569
- ["a control character", "/x\r\ny"],
570
- ])(
571
- "(k) %s fails resolveNextPath, so the toggle is the bare /sign-up",
572
- async (_label, next) => {
573
- await renderPage(next);
574
- expect(screen.getByTestId("auth-card-prospect-link")).toHaveAttribute(
575
- "href",
576
- "/sign-up",
577
- );
578
- },
579
- );
580
-
581
- it("(k) no next: the bare /sign-up", async () => {
582
- await renderPage();
583
- expect(screen.getByTestId("auth-card-prospect-link")).toHaveAttribute(
584
- "href",
585
- "/sign-up",
586
- );
587
- });
588
- });
589
-
590
- // #11095 AC-6 (D7): a returning person's card leads with the provider they
591
- // last launched; a value that does not parse changes nothing.
592
- describe("/sign-in page — the remembered method (#11095 D7)", () => {
593
- it("with ailk-sign-in-method=google: Continue with Google first, no email field, and Use another way restores the card", async () => {
594
- const user = userEvent.setup();
595
- mockGetActiveProviderIds.mockReturnValue(["google", "magic-link"]);
596
- mockCookies["ailk-sign-in-method"] = "google";
597
- await renderPage();
598
- const lead = screen.getByTestId("auth-sso-google");
599
- expect(lead).toHaveTextContent(`${en.signIn.continueWith} ${en.signIn.google}`);
600
- expect(screen.getAllByRole("button")[0]).toBe(lead);
601
- expect(screen.queryByTestId("auth-email")).toBeNull();
602
- const another = screen.getByTestId("sign-in-use-another-way");
603
- expect(another).toHaveTextContent(en.signIn.useAnotherWay);
604
-
605
- await user.click(another);
606
- expect(screen.getByTestId("auth-email")).toBeInTheDocument();
607
- expect(screen.getByTestId("auth-social-google")).toBeInTheDocument();
608
- });
609
-
610
- it.each([
611
- ["evil", ["google", "magic-link"]],
612
- ["github", ["google", "magic-link"]],
613
- ["", ["google", "magic-link"]],
614
- ])(
615
- "a cookie of %j (not an active provider) renders exactly the no-cookie card",
616
- async (value, active) => {
617
- mockGetActiveProviderIds.mockReturnValue(active);
618
- await renderPage();
619
- const today = document.body.innerHTML;
620
- document.body.innerHTML = "";
621
-
622
- mockCookies["ailk-sign-in-method"] = value;
623
- await renderPage();
624
- expect(document.body.innerHTML).toBe(today);
625
- expect(screen.queryByTestId("sign-in-use-another-way")).toBeNull();
626
- },
627
- );
628
- });