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,201 +0,0 @@
1
- /**
2
- * `/[locale]/sign-up` — the site's sign-up page (#5963).
3
- *
4
- * RSC. Branches on `isSignUpOpen()`:
5
- * - open → the sign-up form island, wired to Better Auth exactly as
6
- * `/sign-in`'s island is (providers + method from auth-env).
7
- * With the email sign-in link on, the method is the one-field
8
- * "Send me a magic link" body (#9667 D6): the link creates the
9
- * account on verify, and a failed link lands back here with
10
- * `?error=<code>`, mapped to fixed copy.
11
- * - closed → AuthCard's `invitation` intent: copy only. This is the
12
- * DEFAULT — `apps/web/auth.ts` does not enable
13
- * `emailAndPassword`, so a scaffold offers no public sign-up and
14
- * the page must not advertise one.
15
- *
16
- * The one card (#9662) frames both: the site's mark, "Sign up", the
17
- * "Already have an account? Sign in" line to `/sign-in` (in place of the
18
- * footer's cross-link) and the Terms + Privacy acknowledgement. A closed site
19
- * keeps its invitation copy inside that frame — never a form the server
20
- * would refuse (operator, 2026-10-24).
21
- *
22
- * `?next=` (#9912 D4, D5) is read through `resolveNextPath`, the call
23
- * `/sign-in` makes. The validated `next` is where every method completes —
24
- * the password verification link, the magic link and Google — and both the
25
- * "Sign in" toggle and the failed-link return carry it, so a buyer sent here
26
- * by a spoke's round trip ends back on the spoke. A refused or absent `next`
27
- * gives `/account` and the bare links, as before.
28
- *
29
- * `AuthShell` (the (auth) group's layout) owns the 400px column; the card
30
- * carries the site's mark (#8790 D3).
31
- */
32
-
33
- import { localeHref } from "@working-theory/ui";
34
- import { AuthCard, type AuthCardLabels } from "@working-theory/ui/blocks";
35
- import {
36
- resolveConsentStatement,
37
- SITE_CONSENT_CONFIG_DEFAULTS,
38
- signUpAgreements,
39
- } from "@working-theory/validation";
40
- import type { Metadata } from "next";
41
- import { getTranslations } from "next-intl/server";
42
- import type { ReactElement } from "react";
43
-
44
- import { getActiveProviderIds, isSignUpOpen } from "../../../../lib/auth-env";
45
- import { consentPoliciesFor } from "../../../../lib/consent-policies";
46
- import { siteLogo } from "../../../../lib/site-logo";
47
- import { legalFootnote } from "../legal-footnote";
48
- import { hrefWithNext, resolveNextPath } from "../sign-in/next-path";
49
- import { resolveSignInCardText } from "../sign-in/sign-in-text";
50
-
51
- import { SignUpCard, type SignUpProvider } from "./sign-up-card";
52
-
53
- interface Props {
54
- params: Promise<{ locale: string }>;
55
- searchParams?: Promise<{
56
- next?: string | string[];
57
- error?: string | string[];
58
- }>;
59
- }
60
-
61
- /**
62
- * The magic-link verify's `?error=<code>` (#9667 D6), mapped to fixed copy —
63
- * never the value itself. A repeated `error` reads its first value.
64
- */
65
- const EXPIRED_LINK_ERRORS: ReadonlySet<string> = new Set([
66
- "INVALID_TOKEN",
67
- "new_user_signup_disabled",
68
- ]);
69
-
70
- function linkNoticeKey(
71
- error: string | string[] | undefined,
72
- ): "signUpLinkExpired" | "signUpAgreementsRequired" | "signUpFailed" | null {
73
- if (error === undefined) return null;
74
- const code = Array.isArray(error) ? error[0] : error;
75
- if (code === undefined) return null;
76
- if (EXPIRED_LINK_ERRORS.has(code)) return "signUpLinkExpired";
77
- return code === "AGREEMENTS_REQUIRED"
78
- ? "signUpAgreementsRequired"
79
- : "signUpFailed";
80
- }
81
-
82
- export async function generateMetadata({ params }: Props): Promise<Metadata> {
83
- const { locale } = await params;
84
- const t = await getTranslations({ locale, namespace: "auth" });
85
- return { title: t("signUpTitle"), description: t("signUpDescription") };
86
- }
87
-
88
- export default async function SignUpPage({
89
- params,
90
- searchParams,
91
- }: Props): Promise<ReactElement> {
92
- const { locale } = await params;
93
- const { next: rawNext, error } = (await searchParams) ?? {};
94
- const t = await getTranslations({ locale, namespace: "auth" });
95
- const fallback = localeHref(locale, "/account");
96
- const next = resolveNextPath(rawNext, fallback);
97
- // The toggle line to /sign-in, and the acknowledgement /sign-in shares.
98
- const prospect = {
99
- prompt: t("signUpFooterPrompt"),
100
- linkLabel: t("signUpFooterLink"),
101
- href: hrefWithNext(localeHref(locale, "/sign-in"), next, fallback),
102
- };
103
- const footnote = legalFootnote(
104
- locale,
105
- (await resolveSignInCardText(locale)).acknowledgement,
106
- );
107
-
108
- if (!isSignUpOpen()) {
109
- const closedLabels: AuthCardLabels = {
110
- invitationHeading: t("signUpHeading"),
111
- invitationBody: t("invitationBody"),
112
- };
113
- return (
114
- <div className="flex flex-col gap-4" data-testid="sign-up-page">
115
- <AuthCard
116
- logo={siteLogo()}
117
- intent="invitation"
118
- footer="none"
119
- subhead=""
120
- prospect={prospect}
121
- footnote={footnote}
122
- labels={closedLabels}
123
- />
124
- </div>
125
- );
126
- }
127
-
128
- const active = getActiveProviderIds();
129
- // Exactly the OAuth providers auth-env reports — never a default set.
130
- const providers = active.filter(
131
- (id): id is SignUpProvider => id === "google" || id === "github",
132
- );
133
- const method = active.includes("magic-link")
134
- ? "magic-link"
135
- : active.includes("email")
136
- ? "password"
137
- : "sso";
138
- const noticeKey = method === "magic-link" ? linkNoticeKey(error) : null;
139
-
140
- const labels: AuthCardLabels = {
141
- signUpHeading: t("signUpHeading"),
142
- signUpSubmit: t("signUpSubmit"),
143
- ssoPrefix: t("ssoPrefix"),
144
- google: t("google"),
145
- github: t("github"),
146
- email: t("email"),
147
- password: t("password"),
148
- orContinue: t("orContinue"),
149
- magicLinkSubmit: t("magicLinkSubmit"),
150
- emailLinkDivider: t("orContinue"),
151
- };
152
-
153
- // #8438 D13 — the site's sign-up agreements, resolved to this locale. No
154
- // per-site registry row is wired yet (C1), so this always reads the
155
- // platform default — the same registry the member Privacy tab and the
156
- // account-settings write both read from. Their links resolve through the
157
- // one localized policy map every agreement surface uses (#8765 D9).
158
- const agreements = signUpAgreements(SITE_CONSENT_CONFIG_DEFAULTS).map(
159
- (purpose) => ({
160
- id: purpose.id,
161
- required: purpose.required,
162
- statement: resolveConsentStatement(purpose, locale).statement,
163
- }),
164
- );
165
-
166
- return (
167
- <SignUpCard
168
- logo={siteLogo()}
169
- providers={providers}
170
- method={method}
171
- next={next}
172
- prospect={prospect}
173
- footnote={footnote}
174
- labels={labels}
175
- notConfiguredSubhead={t("signUpNotConfiguredSubhead")}
176
- errorLabels={{
177
- signUpFailed: t("signUpFailed"),
178
- providerFailed: t("providerFailed"),
179
- agreementsRequired: t("signUpAgreementsRequired"),
180
- }}
181
- agreements={agreements}
182
- agreementPolicies={consentPoliciesFor(locale)}
183
- agreementsLegend={t("signUpAgreementsLegend")}
184
- locale={locale}
185
- errorCallbackURL={hrefWithNext(
186
- localeHref(locale, "/sign-up"),
187
- next,
188
- fallback,
189
- )}
190
- {...(noticeKey ? { linkNotice: t(noticeKey) } : {})}
191
- linkLabels={{
192
- sentHeading: t("sentHeading"),
193
- sentSubhead: t("sentSubhead"),
194
- sentBody: t("signUpLinkSentBody"),
195
- back: t("signUpLinkBack"),
196
- failed: t("signUpLinkFailed"),
197
- rateLimited: t("signUpLinkRateLimited"),
198
- }}
199
- />
200
- );
201
- }
@@ -1,366 +0,0 @@
1
- "use client"; // Better Auth's client calls (signUp.email / signIn.social / $fetch) + error state
2
-
3
- /**
4
- * SignUpCard — the /sign-up page's client island (#5963).
5
- *
6
- * The sign-in island's twin: composes `AuthCard` (`intent="sign-up"`) and
7
- * wires its provider buttons / password form to the Better Auth client via
8
- * the shared `useAuthCardFlow` hook (#6018 AC-3) — the same hook
9
- * `SignInCard` next door uses. The page (RSC) decides providers + method from
10
- * auth-env and hands them in; this component never reads env.
11
- *
12
- * Inert until an operator enables `emailAndPassword` server-side — the same
13
- * documented posture the sign-in island already carries for its password
14
- * path. The page only renders this island at all when `isSignUpOpen()`.
15
- *
16
- * The one card (#9662): the page hands in the site's mark (`logo`), the
17
- * "Already have an account? Sign in" line (`prospect`, in place of AuthCard's
18
- * footer cross-link) and the Terms + Privacy acknowledgement (`footnote`).
19
- * The heading stands alone — no subhead unless the card is inert.
20
- *
21
- * Error surface: `AuthCard`'s `errors` prop is per-field, so a failed provider
22
- * launch lands on `errors.email` (the social row sits inside the password form
23
- * beside the email field). The SSO body has no fields, so the same message is
24
- * rendered as an `Alert` above the card for `method="sso"`.
25
- *
26
- * #8438 D13 — the site's sign-up agreements. `AuthCard` has no slot to render
27
- * inside and no external "disabled" hook (packages/ui is not this unit's to
28
- * change), so the card composes its own `ConsentGroup` below `AuthCard` and
29
- * GATES every entry point from the outside: the password submit and every
30
- * provider's click both run through this component's own closures, which do
31
- * nothing until every required agreement is ticked. A wrapping div's
32
- * `aria-disabled` + `pointer-events-none` styling carries the same state
33
- * visually for a mouse/touch pointer in a real browser.
34
- *
35
- * #8765 D10 — the gate above is a convenience; the server decides. The
36
- * password submit sends the ticked ids as `agreements`, with `locale`, in the
37
- * sign-up body, and Better Auth refuses a body without them
38
- * (`AGREEMENTS_REQUIRED`, shown on the agreements, not the password field).
39
- * Each provider click carries the same pair as `signIn.social`'s
40
- * `additionalData`, which Better Auth keeps in the OAuth state for the
41
- * callback. The server writes the grants with the user
42
- * (`lib/sign-up-agreements.ts`); no cookie carries them.
43
- *
44
- * #9667 D6 — the magic-link method. With the email sign-in link on, the card
45
- * is AuthCard's one-field "Send me a magic link" body, gated the same way.
46
- * The request goes through the shared client's `$fetch`, never the
47
- * `magicLinkClient()` plugin (for the reason `sign-in-card.tsx` records), with
48
- * the agreements and locale in its `metadata` — which is what makes it a
49
- * sign-up request. The server binds them to the token and creates the account
50
- * on verify. The sent state never says whether the address had an account.
51
- */
52
-
53
- import {
54
- AuthCard,
55
- ConsentGroup,
56
- type AuthCardLabels,
57
- type AuthSubmitData,
58
- } from "@working-theory/ui/blocks";
59
- import { Alert, AlertDescription } from "@working-theory/ui/primitives";
60
- import { SIGN_UP_AGREEMENTS_FIELD } from "@working-theory/validation";
61
- import {
62
- useRef,
63
- useState,
64
- type MouseEvent,
65
- type ReactElement,
66
- type ReactNode,
67
- } from "react";
68
-
69
- import { authClient, useAuthCardFlow } from "../use-auth-card-flow";
70
-
71
- /** The OAuth providers this page can launch — a subset of AuthCard's. */
72
- export type SignUpProvider = "google" | "github";
73
-
74
- /** One site agreement asked at sign-up (#8438 D1's `signUp` purposes). */
75
- export interface SignUpAgreement {
76
- id: string;
77
- required: boolean;
78
- /** Resolved to the active locale, link tokens included (D1). */
79
- statement: string;
80
- }
81
-
82
- /** Translated copy for the magic-link sign-up (#9667 D6). */
83
- export interface SignUpLinkLabels {
84
- sentHeading: string;
85
- sentSubhead: string;
86
- sentBody: string;
87
- /** The sent state's "Back to sign up" link. */
88
- back: string;
89
- /** Any failed request other than a rate limit or the agreements. */
90
- failed: string;
91
- /** A 429 from Better Auth's per-IP limit. */
92
- rateLimited: string;
93
- }
94
-
95
- export interface SignUpCardProps {
96
- /** The site's mark, centred in the card at 48px (#8790 D3). */
97
- logo?: ReactNode;
98
- /** Active OAuth providers, exactly as auth-env reports them. */
99
- providers: SignUpProvider[];
100
- /**
101
- * "magic-link" when the email sign-in link is active, else "password" when
102
- * the email provider is, otherwise "sso".
103
- */
104
- method: "sso" | "password" | "magic-link";
105
- /** Post-sign-up path. */
106
- next: string;
107
- /** The "Already have an account? Sign in" line to /sign-in (#9662). */
108
- prospect: { prompt: string; linkLabel: string; href: string };
109
- /** The acknowledgement sentence(s) at the card's foot (#9662). */
110
- footnote: ReactNode;
111
- /** Translated AuthCard labels (resolved server-side by the page). */
112
- labels: AuthCardLabels;
113
- /** Subhead shown when no provider is configured. */
114
- notConfiguredSubhead: string;
115
- /** Translated error copy. */
116
- errorLabels: {
117
- signUpFailed: string;
118
- providerFailed: string;
119
- /** Shown on the agreements when the server answers `AGREEMENTS_REQUIRED`. */
120
- agreementsRequired: string;
121
- };
122
- /** The site's `signUp` agreements — always at least `account_terms`. */
123
- agreements: SignUpAgreement[];
124
- /** Policy key → href, for the statements' inline links (D1/D3). */
125
- agreementPolicies: Record<string, string>;
126
- /** The consent fieldset's legend (`auth.signUp.agreementsLegend`). */
127
- agreementsLegend: string;
128
- /** The page's locale, sent with the agreements (the statements' language). */
129
- locale: string;
130
- /** Where a failed link lands (`/sign-up`); Better Auth appends `?error`. */
131
- errorCallbackURL?: string;
132
- /** Fixed copy for a failed link (`?error=` mapped by the page), shown above the card. */
133
- linkNotice?: string;
134
- /** The magic-link method's copy; required when `method` is "magic-link". */
135
- linkLabels?: SignUpLinkLabels;
136
- }
137
-
138
- /** The server's body key for the ticked ids — also the group's control name. */
139
- const AGREEMENTS_FIELD_NAME = SIGN_UP_AGREEMENTS_FIELD;
140
-
141
- /** The server's refusal of a sign-up without the agreements (#8765 D3). */
142
- const AGREEMENTS_REQUIRED = "AGREEMENTS_REQUIRED";
143
-
144
- function errorCode(result: unknown): unknown {
145
- if (typeof result !== "object" || result === null) return undefined;
146
- const error: unknown = Reflect.get(result, "error");
147
- return typeof error === "object" && error !== null
148
- ? Reflect.get(error, "code")
149
- : undefined;
150
- }
151
-
152
- export function SignUpCard({
153
- providers,
154
- method,
155
- next,
156
- prospect,
157
- footnote,
158
- labels,
159
- notConfiguredSubhead,
160
- errorLabels,
161
- agreements,
162
- agreementPolicies,
163
- agreementsLegend,
164
- logo,
165
- locale,
166
- errorCallbackURL,
167
- linkNotice,
168
- linkLabels,
169
- }: SignUpCardProps): ReactElement {
170
- const { errors, providerError, launchProvider, submitPassword } =
171
- useAuthCardFlow(next, {
172
- providerFailed: errorLabels.providerFailed,
173
- passwordFailed: errorLabels.signUpFailed,
174
- });
175
-
176
- const requiredAgreementIds = agreements
177
- .filter((a) => a.required)
178
- .map((a) => a.id);
179
- const [ticked, setTicked] = useState<ReadonlySet<string>>(new Set());
180
- const [agreementsError, setAgreementsError] = useState<string | undefined>(
181
- undefined,
182
- );
183
- const [linkSent, setLinkSent] = useState(false);
184
- const [linkError, setLinkError] = useState<string | undefined>(undefined);
185
- // One request at a time: a double-click would spend two of the per-IP
186
- // sends and mint two live tokens (as sign-in-card.tsx).
187
- const linkPending = useRef(false);
188
- const allAgreed = requiredAgreementIds.every((id) => ticked.has(id));
189
- // What the server checks and records (D10): the ticked ids, in the order shown.
190
- const agreed = (): { agreements: string[]; locale: string } => ({
191
- [SIGN_UP_AGREEMENTS_FIELD]: agreements
192
- .filter((a) => ticked.has(a.id))
193
- .map((a) => a.id),
194
- locale,
195
- });
196
-
197
- // `ConsentGroup`'s checkboxes are uncontrolled, by design (#5275), and
198
- // always start unticked (no `defaults` are ever passed here) — so a click
199
- // on one is always a plain toggle of the LOCAL record below; this never
200
- // reads the Radix root's own post-click DOM state, which a same-tick
201
- // ancestor listener could still see as stale.
202
- function handleAgreementsClick(event: MouseEvent<HTMLDivElement>): void {
203
- const target = (event.target as HTMLElement).closest<HTMLElement>(
204
- '[role="checkbox"]',
205
- );
206
- if (!target?.id) return;
207
- const purposeId = target.id.slice(`${AGREEMENTS_FIELD_NAME}.`.length);
208
- setTicked((previous) => {
209
- const updated = new Set(previous);
210
- if (updated.has(purposeId)) updated.delete(purposeId);
211
- else updated.add(purposeId);
212
- return updated;
213
- });
214
- }
215
-
216
- const notConfigured = method === "sso" && providers.length === 0;
217
-
218
- const providerButtons = providers.map((provider) => ({
219
- provider,
220
- // Gated: a provider launch that would create the account is refused
221
- // until every required agreement is ticked, exactly as the password
222
- // submit below. The agreements ride in the OAuth state (D10).
223
- onClick: () => {
224
- if (!allAgreed) return;
225
- void launchProvider(provider, agreed());
226
- },
227
- }));
228
-
229
- const handleSubmit = (data: AuthSubmitData): void => {
230
- if (!allAgreed) return;
231
- setAgreementsError(undefined);
232
- // Better Auth requires a `name` on email sign-up; this card collects
233
- // none, so the address doubles as the display name until the person
234
- // sets one. Better Auth ignores body keys it does not know, so
235
- // `agreements` and `locale` never reach the User row.
236
- const outcome = authClient.signUp.email({
237
- email: data.email,
238
- password: data.password ?? "",
239
- name: data.email,
240
- callbackURL: next,
241
- ...agreed(),
242
- });
243
- // The agreements refusal belongs to the agreements, not the password
244
- // field; any other failure keeps the password-field message.
245
- void submitPassword(
246
- outcome.then((result) => {
247
- if (errorCode(result) !== AGREEMENTS_REQUIRED) return result;
248
- setAgreementsError(errorLabels.agreementsRequired);
249
- return null;
250
- }),
251
- );
252
- };
253
-
254
- const requestSignUpLink = async (email: string): Promise<void> => {
255
- if (!allAgreed || linkPending.current) return;
256
- linkPending.current = true;
257
- setAgreementsError(undefined);
258
- setLinkError(undefined);
259
- try {
260
- const { error } = await authClient.$fetch("/sign-in/magic-link", {
261
- method: "POST",
262
- body: {
263
- email,
264
- // As the password submit: Better Auth wants a name on a new user.
265
- name: email,
266
- callbackURL: next,
267
- errorCallbackURL,
268
- metadata: agreed(),
269
- },
270
- });
271
- if (!error) {
272
- setLinkSent(true);
273
- return;
274
- }
275
- if (errorCode({ error }) === AGREEMENTS_REQUIRED) {
276
- setAgreementsError(errorLabels.agreementsRequired);
277
- } else {
278
- setLinkError(
279
- error.status === 429 ? linkLabels?.rateLimited : linkLabels?.failed,
280
- );
281
- }
282
- } catch {
283
- setLinkError(linkLabels?.failed);
284
- } finally {
285
- linkPending.current = false;
286
- }
287
- };
288
-
289
- if (method === "magic-link" && linkSent && linkLabels) {
290
- // No `sentTo`: both a new and a taken address get a link, and the state
291
- // must not say which.
292
- return (
293
- <div className="flex flex-col gap-4" data-testid="sign-up-page">
294
- <AuthCard
295
- {...(logo !== undefined ? { logo } : {})}
296
- intent="sent"
297
- footer="cross-link"
298
- // "Back to sign up": this page, where a failed link also lands.
299
- {...(errorCallbackURL !== undefined
300
- ? { signInHref: errorCallbackURL }
301
- : {})}
302
- labels={{
303
- sentHeading: linkLabels.sentHeading,
304
- sentSubhead: linkLabels.sentSubhead,
305
- sentBody: linkLabels.sentBody,
306
- backToSignIn: linkLabels.back,
307
- }}
308
- />
309
- </div>
310
- );
311
- }
312
-
313
- return (
314
- <div className="flex flex-col gap-4" data-testid="sign-up-page">
315
- {linkNotice ? (
316
- <Alert variant="error" data-testid="sign-up-link-notice">
317
- <AlertDescription>{linkNotice}</AlertDescription>
318
- </Alert>
319
- ) : null}
320
- {method === "sso" && providerError ? (
321
- <Alert variant="error" data-testid="sign-up-provider-error">
322
- <AlertDescription>{providerError}</AlertDescription>
323
- </Alert>
324
- ) : null}
325
- <div
326
- aria-disabled={!allAgreed}
327
- className={allAgreed ? undefined : "pointer-events-none opacity-60"}
328
- data-testid="sign-up-card-gate"
329
- >
330
- <AuthCard
331
- {...(logo !== undefined ? { logo } : {})}
332
- intent="sign-up"
333
- method={method}
334
- footer="none"
335
- subhead={notConfigured ? notConfiguredSubhead : ""}
336
- prospect={prospect}
337
- footnote={footnote}
338
- providers={providerButtons}
339
- onSubmit={
340
- method === "magic-link"
341
- ? (data) => void requestSignUpLink(data.email)
342
- : handleSubmit
343
- }
344
- errors={linkError ? { ...errors, email: linkError } : errors}
345
- labels={labels}
346
- />
347
- </div>
348
- {/* eslint-disable-next-line -- delegated-click capture over ConsentGroup's own real `role="checkbox"` descendants (Radix), which are themselves already keyboard-operable and dispatch a native click on Enter/Space; this wrapper adds no interactive semantics of its own and is never itself focused. (Bare directive, not named rules: `jsx-a11y/*` is registered in this monorepo's own lint but not in a scaffolded site's trimmed eslint config.) */}
349
- <div
350
- onClick={handleAgreementsClick}
351
- // Below `md` the card is borderless with a 20px inset; the agreements
352
- // keep that inset so they line up with its fields.
353
- className="px-5 md:px-0"
354
- data-testid="sign-up-agreements"
355
- >
356
- <ConsentGroup
357
- name={AGREEMENTS_FIELD_NAME}
358
- legend={agreementsLegend}
359
- purposes={agreements}
360
- policies={agreementPolicies}
361
- error={agreementsError}
362
- />
363
- </div>
364
- </div>
365
- );
366
- }
@@ -1,116 +0,0 @@
1
- "use client"; // useState + the Better Auth client's browser-side calls
2
-
3
- /**
4
- * useAuthCardFlow — the provider-launch + password-submit boilerplate shared
5
- * by SignInCard and SignUpCard (#6018 AC-3).
6
- *
7
- * Both cards wire an `AuthCard`'s provider buttons and password form to the
8
- * same two moves: launch a Better Auth OAuth provider (a failed launch lands
9
- * the shared `providerFailed` message on the email field, and — for an
10
- * SSO-only card with no fields — as a banner above the card) and submit the
11
- * password form (a failed submit lands a caller-named message on the
12
- * password field).
13
- *
14
- * What differs between sign-in and sign-up is the underlying Better Auth CALL
15
- * itself — `signIn.email(...)` vs `signUp.email(...)`, the latter needing a
16
- * `name` — so `submitPassword` takes the call's own promise as an argument
17
- * rather than owning the choice of which Better Auth method to invoke. The
18
- * single shared `authClient` this module exports is what each card's
19
- * `onSubmit` calls that method on.
20
- */
21
-
22
- import { createAuthClient } from "better-auth/react";
23
- import { useState } from "react";
24
-
25
- export const authClient = createAuthClient();
26
-
27
- /** The OAuth providers either card can launch. */
28
- export type AuthProvider = "google" | "github";
29
-
30
- export interface AuthCardFlowErrorLabels {
31
- /** Shown on a failed OAuth provider launch (shared by both cards). */
32
- providerFailed: string;
33
- /** Shown on a failed password submit — signInFailed or signUpFailed, caller-named. */
34
- passwordFailed: string;
35
- }
36
-
37
- interface FieldErrors {
38
- email?: string;
39
- password?: string;
40
- }
41
-
42
- /** The shape every Better Auth client call this hook awaits resolves to. */
43
- type AuthResult = { error?: unknown } | null | undefined;
44
-
45
- export interface AuthCardFlow {
46
- /** Per-field form errors, in `AuthCard`'s `errors` prop shape. */
47
- errors: FieldErrors;
48
- /** The SSO-body error banner text, or null when none is pending. */
49
- providerError: string | null;
50
- /**
51
- * Launches an OAuth provider via `signIn.social`. `additionalData` rides
52
- * in Better Auth's OAuth state to the callback — the sign-up card's ticked
53
- * agreements and locale (#8765 D10); the sign-in card passes none.
54
- */
55
- launchProvider: (
56
- provider: AuthProvider,
57
- additionalData?: Record<string, unknown>,
58
- ) => Promise<void>;
59
- /**
60
- * Awaits the caller's own Better Auth call (`signIn.email(...)` or
61
- * `signUp.email(...)`) and surfaces a `{ error }` result — or a rejection —
62
- * on the password field.
63
- */
64
- submitPassword: (action: Promise<AuthResult>) => Promise<void>;
65
- }
66
-
67
- /**
68
- * @param next - the post-auth `callbackURL` every provider launch uses.
69
- * @param errorLabels - translated copy for the two failure cases.
70
- */
71
- export function useAuthCardFlow(
72
- next: string,
73
- errorLabels: AuthCardFlowErrorLabels,
74
- ): AuthCardFlow {
75
- const [errors, setErrors] = useState<FieldErrors>({});
76
- const [providerError, setProviderError] = useState<string | null>(null);
77
-
78
- const launchProvider = async (
79
- provider: AuthProvider,
80
- additionalData?: Record<string, unknown>,
81
- ): Promise<void> => {
82
- setProviderError(null);
83
- // Better Auth reports a failed launch as `{ error }`; a network/runtime
84
- // failure rejects. Both land on the same providerFailed message.
85
- const failed = await authClient.signIn
86
- .social({
87
- provider,
88
- callbackURL: next,
89
- ...(additionalData ? { additionalData } : {}),
90
- })
91
- .then(
92
- (res: AuthResult) => Boolean(res?.error),
93
- () => true,
94
- );
95
- if (failed) {
96
- setProviderError(errorLabels.providerFailed);
97
- setErrors((prev) => ({ ...prev, email: errorLabels.providerFailed }));
98
- }
99
- };
100
-
101
- const submitPassword = async (action: Promise<AuthResult>): Promise<void> => {
102
- setErrors({});
103
- // Mirrors launchProvider's own resilience: a `{ error }` result AND a
104
- // rejected promise both land on the same passwordFailed message, so a
105
- // network/runtime failure from the caller's signIn.email/signUp.email
106
- // call surfaces in the form rather than becoming an unhandled rejection
107
- // (code review, #6018).
108
- const failed = await action.then(
109
- (res) => Boolean(res?.error),
110
- () => true,
111
- );
112
- if (failed) setErrors({ password: errorLabels.passwordFailed });
113
- };
114
-
115
- return { errors, providerError, launchProvider, submitPassword };
116
- }