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,106 +0,0 @@
1
- /**
2
- * The spoke's Security tab asks for a password link (#11162) —
3
- * `POST /api/hub-session/password`.
4
- *
5
- * On a spoke that signs in through its hub, the Security tab renders the
6
- * Password row itself; its Set / Change password button posts here. This
7
- * route asks the hub web, server to server as the spoke's client, to mail the
8
- * SIGNED-IN person the hub's own set-password link — the person comes from
9
- * the sealed session cookie, never from the body, so a spoke cannot ask for
10
- * anyone it did not sign in. The link lands on the hub's set-password page,
11
- * which returns the person to this site's `/account/security`.
12
- *
13
- * 1. 404 unless `SIGN_IN_PROVIDER` is `"hub"`; not configured → 503.
14
- * 2. Same-origin only (`Sec-Fetch-Site`, `Origin`), else 403.
15
- * 3. No session cookie, or one that does not open → 401.
16
- * 4. 10 posts per visitor per 10 minutes (429), then the bot check (503).
17
- * 5. The body is `spokePasswordBodySchema`: `{ locale }` and nothing else —
18
- * a `password` key, or any other, is 400. The spoke never holds or
19
- * accepts a password.
20
- * 6. The hub web's `POST /api/auth/hub/password` gets the client, its
21
- * callback, the session's credential, the locale and the return path
22
- * (`/account/security` under that locale); the hub API checks the
23
- * client and the credential before anything is mailed.
24
- * 7. 202 `{ sent: true }`; the hub's `invalid_grant` (a credential it no
25
- * longer honours) → 401; anything else → 503.
26
- *
27
- * Nothing here logs the credential, the cookie or an address. Every answer
28
- * is `Cache-Control: no-store`.
29
- */
30
- import { spokePasswordBodySchema } from "@working-theory/validation";
31
-
32
- import { runBotCheck } from "../../../../lib/bot-check";
33
- import { hubSessionConfig } from "../../../../lib/hub-session/config";
34
- import { hubError, localeOfPath, postToHub, readBodyText } from "../../../../lib/hub-session/entry";
35
- import { isSameOrigin, readHubSessionPayload } from "../../../../lib/hub-session/session";
36
- import { SIGN_IN_PROVIDER } from "../../../../lib/topology.generated";
37
- import { takeVisitorLimit } from "../../../../src/lib/rate-limit";
38
-
39
- /** The hub web's password route. */
40
- const HUB_PASSWORD_PATH = "/api/auth/hub/password";
41
-
42
- /** The per-visitor budget for this route. */
43
- const VISITOR_LIMIT = 10;
44
- const VISITOR_WINDOW_MS = 10 * 60_000;
45
-
46
- const DEFAULT_LOCALE = "en";
47
-
48
- function json(status: number, body: Record<string, unknown>): Response {
49
- return new Response(JSON.stringify(body), {
50
- status,
51
- headers: { "Content-Type": "application/json", "Cache-Control": "no-store" },
52
- });
53
- }
54
-
55
- const refuse = (status: number, error: string): Response => json(status, { error });
56
-
57
- /** The parsed JSON body, or `undefined` when it is too large or does not parse. */
58
- async function readJson(request: Request): Promise<unknown> {
59
- const text = await readBodyText(request);
60
- if (text === null) return undefined;
61
- try {
62
- return JSON.parse(text) as unknown;
63
- } catch {
64
- return undefined;
65
- }
66
- }
67
-
68
- // platform-decisions-waiver: api-versioning — a sign-in step of the spoke's own form, not a versioned API contract (spec 11096 §6)
69
- export async function POST(request: Request): Promise<Response> {
70
- if (SIGN_IN_PROVIDER !== "hub") return new Response(null, { status: 404 });
71
- const config = hubSessionConfig();
72
- if (config === null) return refuse(503, "temporarily_unavailable");
73
- if (!isSameOrigin(request, config.siteOrigin)) return refuse(403, "forbidden");
74
-
75
- const session = readHubSessionPayload(request.headers);
76
- if (session === null) return refuse(401, "no_session");
77
-
78
- if (!takeVisitorLimit("hub-session-password", request.headers, VISITOR_LIMIT, VISITOR_WINDOW_MS).allowed) {
79
- return refuse(429, "rate_limited");
80
- }
81
- const bot = await runBotCheck({ source: "hub-session", target: "password", scope: "write" });
82
- if (bot !== "pass") return refuse(503, "temporarily_unavailable");
83
-
84
- const parsed = spokePasswordBodySchema.safeParse(await readJson(request));
85
- if (!parsed.success) return refuse(400, "invalid_request");
86
- // An enabled locale, else the default — the one the Security tab is under.
87
- const locale = localeOfPath(`/${parsed.data.locale}`);
88
-
89
- const answer = await postToHub(config, HUB_PASSWORD_PATH, {
90
- client_id: config.clientId,
91
- redirect_uri: config.redirectUri,
92
- access_token: session.accessToken,
93
- locale,
94
- return_path: `${locale === DEFAULT_LOCALE ? "" : `/${locale}`}/account/security`,
95
- });
96
-
97
- if (answer?.status === 202) return json(202, { sent: true });
98
- if (answer?.status === 400 && hubError(answer) === "invalid_grant") {
99
- return refuse(401, "invalid_session");
100
- }
101
- // The hub's error code is a closed enum, never an address.
102
- console.warn(
103
- `[hub-session] password link not sent status=${answer === null ? "unreachable" : answer.status} error=${hubError(answer) ?? "none"}`,
104
- );
105
- return refuse(503, "temporarily_unavailable");
106
- }
@@ -1,91 +0,0 @@
1
- /**
2
- * Start a sign-in through the hub (#7894 D2, D7) — `GET /api/hub-session/sign-in?next=<path>`.
3
- *
4
- * Mints a `state` and a PKCE verifier (32 random bytes each, base64url), seals
5
- * them with the sanitized `next` into the flow cookie for ten minutes, and
6
- * sends the visitor to the hub's `/api/auth/hub/authorize` with the S256
7
- * challenge. The redirect URI is this site's configured origin plus
8
- * `/api/hub-session/callback` — never derived from the request's `Host`.
9
- *
10
- * - not a hub-mode spoke (`SIGN_IN_PROVIDER` is not `"hub"`): 404;
11
- * - hub mode but not configured: 303 to the site's home (#11095 D4) —
12
- * `/account` would redirect straight back here.
13
- *
14
- * Hinted email (#8757 D9): a single `?email=` that `accountEmailHintSchema`
15
- * accepts rides to the hub as `login_hint`, so its sign-in form opens with
16
- * the address typed. A refused or repeated value is dropped. The hint goes on
17
- * the authorize URL only — never into the sealed flow cookie.
18
- *
19
- * Sign-up hint (#9912 D2): exactly one `?prompt=create` (the gate's "Sign up")
20
- * rides to the hub as `prompt=create`, so a visitor with no hub session lands
21
- * on its sign-up screen instead of sign-in; the round trip is otherwise the
22
- * same. Any other value, an empty or a repeated one adds nothing, and the hint
23
- * never enters the flow cookie.
24
- *
25
- * Google (#11096 D4): exactly one `?provider=google` (the spoke form's
26
- * "Continue with Google") rides to the hub as `provider_hint=google`, which
27
- * sends a visitor with no hub session straight to Google, with no sign-in
28
- * card. Any other value, an empty or a repeated one adds nothing, and the
29
- * hint never enters the flow cookie.
30
- *
31
- * Nothing here logs the state, the verifier or the challenge.
32
- */
33
- import { accountEmailHintSchema } from "@working-theory/validation";
34
-
35
- import { hubSessionConfig } from "../../../../lib/hub-session/config";
36
- import {
37
- HUB_SESSION_HOME_PATH,
38
- seeOther,
39
- startHubFlow,
40
- } from "../../../../lib/hub-session/session";
41
- import { SIGN_IN_PROVIDER } from "../../../../lib/topology.generated";
42
-
43
- /** The hub's browser step (spec 7894 D4). */
44
- const AUTHORIZE_PATH = "/api/auth/hub/authorize";
45
-
46
- /** #8757 D9 — the one `email` the hint schema accepts; repeated or refused → none. */
47
- function emailHint(params: URLSearchParams): string | undefined {
48
- const values = params.getAll("email");
49
- if (values.length !== 1) return undefined;
50
- const parsed = accountEmailHintSchema.safeParse(values[0]);
51
- return parsed.success ? parsed.data : undefined;
52
- }
53
-
54
- /** #9912 D2 — `"create"` when the one `prompt` is exactly that, else none. */
55
- function signUpHint(params: URLSearchParams): "create" | undefined {
56
- const values = params.getAll("prompt");
57
- return values.length === 1 && values[0] === "create" ? "create" : undefined;
58
- }
59
-
60
- /** #11096 D4 — `"google"` when the one `provider` is exactly that, else none. */
61
- function providerHint(params: URLSearchParams): "google" | undefined {
62
- const values = params.getAll("provider");
63
- return values.length === 1 && values[0] === "google" ? "google" : undefined;
64
- }
65
-
66
- // platform-decisions-waiver: api-versioning — sign-in redirect endpoint, not a versioned API contract (spec 7894 §7)
67
- export function GET(request: Request): Response {
68
- if (SIGN_IN_PROVIDER !== "hub") return new Response(null, { status: 404 });
69
- const config = hubSessionConfig();
70
- if (config === null) return seeOther(HUB_SESSION_HOME_PATH);
71
-
72
- const params = new URL(request.url).searchParams;
73
- const flow = startHubFlow(config, params.get("next"));
74
-
75
- const authorize = new URL(AUTHORIZE_PATH, config.hubOrigin);
76
- const query = new URLSearchParams({
77
- response_type: "code",
78
- client_id: config.clientId,
79
- redirect_uri: config.redirectUri,
80
- state: flow.state,
81
- code_challenge: flow.challenge,
82
- code_challenge_method: "S256",
83
- });
84
- if (signUpHint(params) !== undefined) query.set("prompt", "create");
85
- const loginHint = emailHint(params);
86
- if (loginHint !== undefined) query.set("login_hint", loginHint);
87
- if (providerHint(params) !== undefined) query.set("provider_hint", "google");
88
- authorize.search = query.toString();
89
-
90
- return seeOther(authorize.toString(), [flow.cookie]);
91
- }
@@ -1,54 +0,0 @@
1
- /**
2
- * Sign out of a spoke that signs in through its hub (#7894 D7) — `POST /api/hub-session/sign-out`.
3
- *
4
- * The signed-in Nav's "Sign out" posts here (`SIGN_OUT_ENDPOINT`). It revokes
5
- * the credential at the hub (best-effort: a hub that cannot be reached still
6
- * leaves the visitor signed out here), clears the session cookie and answers
7
- * 204.
8
- *
9
- * Same-origin only: a `Sec-Fetch-Site` other than `same-origin`, an `Origin`
10
- * that is not this site's configured origin, or a request carrying neither is
11
- * refused 403 before anything is revoked, so another site cannot sign a
12
- * visitor out. POST only — Next answers 405 to any other method.
13
- */
14
- import { hubSignIn } from "@working-theory/api-client";
15
-
16
- import { hubSessionConfig } from "../../../../lib/hub-session/config";
17
- import {
18
- cookieHeader,
19
- isSameOrigin,
20
- readHubSessionPayload,
21
- sessionCookieName,
22
- } from "../../../../lib/hub-session/session";
23
- import { SIGN_IN_PROVIDER } from "../../../../lib/topology.generated";
24
-
25
- // platform-decisions-waiver: api-versioning — sign-in redirect endpoint, not a versioned API contract (spec 7894 §7)
26
- export async function POST(request: Request): Promise<Response> {
27
- if (SIGN_IN_PROVIDER !== "hub") return new Response(null, { status: 404 });
28
- const config = hubSessionConfig();
29
- if (!isSameOrigin(request, config?.siteOrigin ?? null)) {
30
- return new Response(null, { status: 403 });
31
- }
32
- if (config === null) return new Response(null, { status: 204 });
33
-
34
- const payload = readHubSessionPayload(request.headers);
35
- if (payload !== null) {
36
- try {
37
- await hubSignIn.revoke(
38
- { clientId: config.clientId, clientSecret: config.clientSecret },
39
- { accessToken: payload.accessToken },
40
- );
41
- } catch (err) {
42
- console.error(
43
- `[hub-session] revoke failed errName=${err instanceof Error ? err.name : "unknown"}`,
44
- );
45
- }
46
- }
47
- return new Response(null, {
48
- status: 204,
49
- headers: {
50
- "Cache-Control": "no-store",
51
- "Set-Cookie": cookieHeader(sessionCookieName(config), "", 0, config),
52
- },
53
- });
54
- }
@@ -1,62 +0,0 @@
1
- "use client"; // Better Auth's client signOut + router navigation need the browser
2
-
3
- /**
4
- * SignOutTrigger — wraps the signed-in Nav's "Sign out" trigger (#4984).
5
- *
6
- * With an `endpoint` (a spoke that signs in through its hub, #7894 D10) it
7
- * POSTs there — the hub-session sign-out, which revokes the credential and
8
- * clears the session cookie — and navigates home only when that succeeded;
9
- * without one it calls Better Auth's client exactly as before.
10
- *
11
- * The locale layout (RSC) reads the session and authors the "Sign out" nav
12
- * action as `kind: "flow"`; Nav hands the rendered trigger `<Button>` back
13
- * through `renderFlowTrigger` — composed in a client Nav until #11095 D6, on the client side
14
- * of the RSC boundary (#7402) — and this component clones it with the real
15
- * sign-out handler. Same `createAuthClient()` idiom as `SignInGate`.
16
- */
17
-
18
- import { createAuthClient } from "better-auth/react";
19
- import { useRouter } from "next/navigation";
20
- import type { ReactElement, ReactNode } from "react";
21
- import { cloneElement, isValidElement } from "react";
22
-
23
- const authClient = createAuthClient();
24
-
25
- export interface SignOutTriggerProps {
26
- /** The Nav-rendered trigger button. */
27
- children: ReactNode;
28
- /** Where to land after signing out. Defaults to the site home. */
29
- homeHref?: string;
30
- /** A same-origin sign-out route to POST to instead of Better Auth's client. */
31
- endpoint?: string;
32
- }
33
-
34
- export function SignOutTrigger({
35
- children,
36
- homeHref = "/",
37
- endpoint,
38
- }: SignOutTriggerProps): ReactElement {
39
- const router = useRouter();
40
-
41
- const handleSignOut = async (): Promise<void> => {
42
- if (endpoint !== undefined) {
43
- // A refused or failed sign-out leaves the visitor signed in, so the
44
- // page must not pretend otherwise by navigating away.
45
- try {
46
- const res = await fetch(endpoint, { method: "POST", credentials: "same-origin" });
47
- if (!res.ok) return;
48
- } catch {
49
- return;
50
- }
51
- } else {
52
- await authClient.signOut();
53
- }
54
- router.push(homeHref);
55
- router.refresh();
56
- };
57
-
58
- if (!isValidElement(children)) return <>{children}</>;
59
- return cloneElement(children as ReactElement<{ onClick?: () => void }>, {
60
- onClick: () => void handleSignOut(),
61
- });
62
- }
@@ -1,140 +0,0 @@
1
- /**
2
- * Tests for the auth-route predicate (#5963).
3
- *
4
- * `isAuthPath()` is the ONE list the locale layout branches on and the five
5
- * `(auth)` page segments are named from, so the layout and the routes cannot
6
- * drift. Covers bare paths, locale-prefixed paths, near misses, nested paths,
7
- * and the absent-header fail-safe — and the same for `isAccountPath()` (#7430).
8
- */
9
-
10
- import { AUTH_SEGMENTS, isAccountPath, isAuthPath, isBookingPath } from "../auth-routes";
11
-
12
- const LOCALES = ["en", "fr", "de"];
13
-
14
- describe("AUTH_SEGMENTS", () => {
15
- it("names exactly the six auth routes", () => {
16
- expect([...AUTH_SEGMENTS]).toEqual([
17
- "sign-in",
18
- "sign-up",
19
- "forgot-password",
20
- "reset-password",
21
- "verify-email",
22
- "consent",
23
- ]);
24
- });
25
- });
26
-
27
- describe("isAuthPath", () => {
28
- it.each(AUTH_SEGMENTS)("matches the bare /%s path", (segment) => {
29
- expect(isAuthPath(`/${segment}`, LOCALES)).toBe(true);
30
- });
31
-
32
- it.each(AUTH_SEGMENTS)("matches the locale-prefixed /fr/%s path", (segment) => {
33
- expect(isAuthPath(`/fr/${segment}`, LOCALES)).toBe(true);
34
- });
35
-
36
- it("matches a trailing-slash auth path", () => {
37
- expect(isAuthPath("/sign-in/", LOCALES)).toBe(true);
38
- });
39
-
40
- it("matches an auth path carrying a query string", () => {
41
- expect(isAuthPath("/sign-in?next=/account", LOCALES)).toBe(true);
42
- });
43
-
44
- it("matches a nested path under an auth segment", () => {
45
- expect(isAuthPath("/reset-password/confirm", LOCALES)).toBe(true);
46
- });
47
-
48
- it("does not match a near miss", () => {
49
- expect(isAuthPath("/sign-in-x", LOCALES)).toBe(false);
50
- expect(isAuthPath("/sign", LOCALES)).toBe(false);
51
- });
52
-
53
- it("does not match a marketing path", () => {
54
- expect(isAuthPath("/pricing", LOCALES)).toBe(false);
55
- expect(isAuthPath("/fr/pricing", LOCALES)).toBe(false);
56
- });
57
-
58
- it("does not match the locale root or the site root", () => {
59
- expect(isAuthPath("/", LOCALES)).toBe(false);
60
- expect(isAuthPath("/fr", LOCALES)).toBe(false);
61
- });
62
-
63
- it("does not strip a prefix that is not an enabled locale", () => {
64
- // `/es` is not enabled here, so `es` is the first segment, not a prefix.
65
- expect(isAuthPath("/es/sign-in", LOCALES)).toBe(false);
66
- });
67
-
68
- it("fails to NOT-an-auth-path for an empty or absent pathname", () => {
69
- // The fail-safe direction (§ D1): an absent `x-pathname` must never strip
70
- // a marketing page's chrome. The worst case is an auth page WITH chrome,
71
- // which the (auth) group's own tests catch.
72
- expect(isAuthPath("", LOCALES)).toBe(false);
73
- expect(isAuthPath(undefined, LOCALES)).toBe(false);
74
- });
75
- });
76
-
77
- describe("isAccountPath (#7430, spec 7423 D4)", () => {
78
- it("matches the account root, bare and locale-prefixed", () => {
79
- expect(isAccountPath("/account", LOCALES)).toBe(true);
80
- expect(isAccountPath("/en/account", LOCALES)).toBe(true);
81
- expect(isAccountPath("/fr/account", LOCALES)).toBe(true);
82
- });
83
-
84
- it("matches every path under /account", () => {
85
- expect(isAccountPath("/account/settings", LOCALES)).toBe(true);
86
- expect(isAccountPath("/account/support", LOCALES)).toBe(true);
87
- expect(isAccountPath("/fr/account/inbox/purchase/fc_1", LOCALES)).toBe(true);
88
- });
89
-
90
- it("matches a trailing slash and a query string", () => {
91
- expect(isAccountPath("/account/", LOCALES)).toBe(true);
92
- expect(isAccountPath("/account?tab=all", LOCALES)).toBe(true);
93
- });
94
-
95
- it("does not match a near miss or a marketing path", () => {
96
- expect(isAccountPath("/accounts", LOCALES)).toBe(false);
97
- expect(isAccountPath("/about", LOCALES)).toBe(false);
98
- expect(isAccountPath("/blog/account", LOCALES)).toBe(false);
99
- });
100
-
101
- it("does not match an auth path", () => {
102
- expect(isAccountPath("/sign-in?next=/account", LOCALES)).toBe(false);
103
- });
104
-
105
- it("does not strip a prefix that is not an enabled locale", () => {
106
- expect(isAccountPath("/es/account", LOCALES)).toBe(false);
107
- });
108
-
109
- it("fails to NOT-an-account-path for an empty or absent pathname", () => {
110
- expect(isAccountPath("", LOCALES)).toBe(false);
111
- expect(isAccountPath(undefined, LOCALES)).toBe(false);
112
- expect(isAccountPath(null, LOCALES)).toBe(false);
113
- });
114
- });
115
-
116
- // #8843 D10 — the booking pages render without the marketing chrome.
117
- describe("isBookingPath (#8843)", () => {
118
- it("matches /meet, a meeting page and /private, bare or locale-prefixed", () => {
119
- for (const path of ["/meet", "/meet/", "/meet/intro", "/en/meet/intro", "/fr/meet", "/private", "/fr/private"]) {
120
- expect(isBookingPath(path, LOCALES)).toBe(true);
121
- }
122
- });
123
-
124
- it("does not match the confirmation page, which keeps the marketing chrome", () => {
125
- expect(isBookingPath("/meet/confirmed", LOCALES)).toBe(false);
126
- expect(isBookingPath("/fr/meet/confirmed", LOCALES)).toBe(false);
127
- });
128
-
129
- it("does not match a near miss or a marketing path", () => {
130
- expect(isBookingPath("/meeting", LOCALES)).toBe(false);
131
- expect(isBookingPath("/privacy", LOCALES)).toBe(false);
132
- expect(isBookingPath("/blog/meet", LOCALES)).toBe(false);
133
- });
134
-
135
- it("fails to NOT-a-booking-path for an empty or absent pathname", () => {
136
- expect(isBookingPath("", LOCALES)).toBe(false);
137
- expect(isBookingPath(undefined, LOCALES)).toBe(false);
138
- expect(isBookingPath(null, LOCALES)).toBe(false);
139
- });
140
- });
@@ -1,125 +0,0 @@
1
- /**
2
- * The auth route group's segment list and its path predicate (#5963).
3
- *
4
- * ONE module, so the list `app/[locale]/layout.tsx` branches on to drop the
5
- * marketing chrome and the list the `(auth)` group's page segments exist at
6
- * cannot drift. A route group contributes no URL segment, so these are the
7
- * real paths: `/sign-in`, `/sign-up`, `/forgot-password`, `/reset-password`,
8
- * `/verify-email` and the MCP consent step `/consent` (#10357), each under next-intl's `as-needed` prefixing (bare for
9
- * the default locale, `/<locale>/…` otherwise).
10
- *
11
- * `isAccountPath()` (#7430, spec 7423 D4) is the same predicate for the
12
- * signed-in account area — `/account` and everything under it — which the
13
- * layout also renders without the marketing chrome.
14
- *
15
- * `isBookingPath()` (#8843 D10) is the same predicate for the scheduling
16
- * module's booking pages — `/meet`, `/meet/<slug>` and `/private`, never
17
- * `/meet/confirmed`, plus the member's own booking page
18
- * `/account/appointments/<slug>` (#11154) — which the layout renders
19
- * chrome-free only where the module is installed (`lib/modules.generated.ts`)
20
- * and the middleware grants the scheduling CSP. This module imports nothing,
21
- * so edge code can import it too.
22
- *
23
- * No Next.js import — pure functions, asserted directly by their own suite.
24
- */
25
-
26
- /** The six segments the `(auth)` route group serves. */
27
- export const AUTH_SEGMENTS = [
28
- "sign-in",
29
- "sign-up",
30
- "forgot-password",
31
- "reset-password",
32
- "verify-email",
33
- // The MCP consent step (#10357 D6).
34
- "consent",
35
- ] as const;
36
-
37
- export type AuthSegment = (typeof AUTH_SEGMENTS)[number];
38
-
39
- /**
40
- * Whether `pathname` addresses one of the five auth routes.
41
- *
42
- * Locale-prefix-aware the same way `resolveLocalePath()` is: strip a leading
43
- * `/<locale>` when it matches an ENABLED locale, then compare the first
44
- * remaining segment against the list. A prefix that is not an enabled locale
45
- * is a first segment, not a prefix.
46
- *
47
- * Fail-safe direction: an absent or empty pathname answers `false`. The
48
- * layout's branch reads a header that can legitimately be missing (a direct
49
- * render in a unit test, a path the middleware matcher excludes), and a
50
- * missing header must never strip a marketing page's chrome. The worst case
51
- * is an auth page that renders WITH chrome, which the group's own tests catch.
52
- */
53
- export function isAuthPath(
54
- pathname: string | undefined | null,
55
- locales: readonly string[],
56
- ): boolean {
57
- const first = firstSegment(pathname, locales);
58
- return AUTH_SEGMENTS.some((segment) => segment === first);
59
- }
60
-
61
- /**
62
- * Whether `pathname` addresses the account area: `/account` or any path
63
- * under it, bare or locale-prefixed (spec 7423 D4). The same prefix rule and
64
- * the same fail-safe direction as `isAuthPath()` — an absent or empty
65
- * pathname answers `false`, so a missing header never strips a marketing
66
- * page's chrome.
67
- */
68
- export function isAccountPath(
69
- pathname: string | undefined | null,
70
- locales: readonly string[],
71
- ): boolean {
72
- return firstSegment(pathname, locales) === "account";
73
- }
74
-
75
- /**
76
- * Whether `pathname` addresses a booking page: `/private`, `/meet`, or
77
- * `/meet/<slug>` for any slug but `confirmed` (the booker's confirmation
78
- * page, which keeps the marketing chrome), or the member's booking page
79
- * `/account/appointments/<slug>` (#11154) — never the Appointments list
80
- * itself, which embeds nothing. The same prefix rule and the same fail-safe
81
- * direction as `isAuthPath()`.
82
- */
83
- export function isBookingPath(
84
- pathname: string | undefined | null,
85
- locales: readonly string[],
86
- ): boolean {
87
- const [first, second, third] = segments(pathname, locales);
88
- if (first === "private") return true;
89
- if (first === "account") return second === "appointments" && third !== undefined;
90
- return first === "meet" && second !== "confirmed";
91
- }
92
-
93
- /**
94
- * The first path segment after an enabled-locale prefix, or `undefined` for
95
- * an absent or empty pathname.
96
- */
97
- function firstSegment(
98
- pathname: string | undefined | null,
99
- locales: readonly string[],
100
- ): string | undefined {
101
- return segments(pathname, locales)[0];
102
- }
103
-
104
- /**
105
- * The path's segments after an enabled-locale prefix (empty for an absent or
106
- * empty pathname). A trailing slash adds no segment.
107
- */
108
- function segments(
109
- pathname: string | undefined | null,
110
- locales: readonly string[],
111
- ): string[] {
112
- if (!pathname) return [];
113
-
114
- // Drop a query string / fragment — `x-pathname` carries the path, but a
115
- // caller passing a full request path should get the same verdict.
116
- const path = pathname.split(/[?#]/)[0] ?? "";
117
- const bare =
118
- locales.length > 0
119
- ? path.replace(new RegExp(`^/(${locales.join("|")})(?=/|$)`), "")
120
- : path;
121
-
122
- const parts = bare.split("/").slice(1);
123
- if (parts.at(-1) === "") parts.pop();
124
- return parts;
125
- }