create-ailk 0.35.1 → 0.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/README.md +1 -1
  2. package/component-catalog.json +12 -1
  3. package/component-catalog.md +6 -5
  4. package/dist/lib/env-catalog.js +8 -0
  5. package/dist/surfaces.js +6 -3
  6. package/dist/topology.d.ts +4 -4
  7. package/dist/topology.js +104 -60
  8. package/package.json +3 -3
  9. package/templates/.env.example +21 -0
  10. package/templates/apps/api/.env.example +7 -0
  11. package/templates/apps/api/CLAUDE.md +9 -4
  12. package/templates/apps/mcp/CLAUDE.md +4 -2
  13. package/templates/apps/web/.env.example +16 -0
  14. package/templates/apps/web/CLAUDE.md +46 -5
  15. package/templates/apps/web/app/[locale]/(auth)/__tests__/password-reset.test.tsx +2 -0
  16. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/page.test.tsx +52 -1
  17. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/remembered-method.test.ts +43 -0
  18. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/sign-in-card.test.tsx +108 -1
  19. package/templates/apps/web/app/[locale]/(auth)/sign-in/page.tsx +36 -3
  20. package/templates/apps/web/app/[locale]/(auth)/sign-in/remembered-method.ts +37 -0
  21. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-card.tsx +90 -33
  22. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-text.ts +9 -4
  23. package/templates/apps/web/app/[locale]/(authed)/__tests__/gate.test.tsx +79 -348
  24. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +12 -1
  25. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +55 -2
  26. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout-sign-out.test.tsx +10 -5
  27. package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +1 -1
  28. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +60 -6
  29. package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +32 -3
  30. package/templates/apps/web/app/[locale]/(authed)/account/connect/__tests__/page.test.tsx +8 -1
  31. package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +7 -3
  32. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/phone-verification.test.tsx +215 -0
  33. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/seam-imports.test.ts +65 -0
  34. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +47 -0
  35. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-actions.ts +122 -0
  36. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +214 -0
  37. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/invitation-id.test.ts +35 -0
  38. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/page.test.tsx +266 -0
  39. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/actions.ts +116 -0
  40. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/invitation-id.ts +12 -0
  41. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +154 -0
  42. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +6 -4
  43. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +3 -1
  44. package/templates/apps/web/app/[locale]/(authed)/layout.tsx +15 -13
  45. package/templates/apps/web/app/[locale]/(authed)/signed-out-gate.generated.tsx +20 -52
  46. package/templates/apps/web/app/[locale]/layout.tsx +24 -75
  47. package/templates/apps/web/app/[locale]/purchase/__tests__/success.test.tsx +50 -0
  48. package/templates/apps/web/app/[locale]/purchase/success/page.tsx +48 -7
  49. package/templates/apps/web/app/api/auth/hub/__tests__/entry-routes.test.ts +749 -0
  50. package/templates/apps/web/app/api/auth/hub/authorize/__tests__/route.test.ts +166 -7
  51. package/templates/apps/web/app/api/auth/hub/authorize/route.ts +96 -30
  52. package/templates/apps/web/app/api/auth/hub/continuation.ts +51 -2
  53. package/templates/apps/web/app/api/auth/hub/email/route.ts +111 -0
  54. package/templates/apps/web/app/api/auth/hub/entry-shared.ts +163 -0
  55. package/templates/apps/web/app/api/auth/hub/purchase/route.ts +230 -0
  56. package/templates/apps/web/app/api/auth/hub/purchase-link/route.ts +174 -0
  57. package/templates/apps/web/app/api/auth/hub/sign-up/route.ts +60 -0
  58. package/templates/apps/web/app/api/auth/hub/sign-up-evidence.ts +97 -0
  59. package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +475 -7
  60. package/templates/apps/web/app/api/hub-session/callback/route.ts +13 -47
  61. package/templates/apps/web/app/api/hub-session/email/route.ts +125 -0
  62. package/templates/apps/web/app/api/hub-session/one-tap/nonce/route.ts +49 -0
  63. package/templates/apps/web/app/api/hub-session/one-tap/route.ts +106 -0
  64. package/templates/apps/web/app/api/hub-session/open/route.ts +111 -0
  65. package/templates/apps/web/app/api/hub-session/sign-in/route.ts +23 -40
  66. package/templates/apps/web/app/api/hub-session/sign-out/route.ts +1 -10
  67. package/templates/apps/web/auth.ts +133 -6
  68. package/templates/apps/web/components/sign-out-trigger.tsx +1 -1
  69. package/templates/apps/web/lib/__tests__/auth-email.test.ts +141 -0
  70. package/templates/apps/web/lib/__tests__/auth-phone.test.ts +445 -0
  71. package/templates/apps/web/lib/__tests__/auth-sms.test.ts +140 -0
  72. package/templates/apps/web/lib/__tests__/fixtures/tsconfig.flow.json +18 -0
  73. package/templates/apps/web/lib/__tests__/site-header.test.ts +13 -0
  74. package/templates/apps/web/lib/__tests__/telemetry-scrub.test.ts +19 -1
  75. package/templates/apps/web/lib/auth-email.ts +62 -6
  76. package/templates/apps/web/lib/auth-env.ts +13 -0
  77. package/templates/apps/web/lib/auth-sms.ts +180 -0
  78. package/templates/apps/web/lib/hub-session/__tests__/hub-session.test.ts +28 -0
  79. package/templates/apps/web/lib/hub-session/__tests__/spoke-sign-in.test.tsx +332 -0
  80. package/templates/apps/web/lib/hub-session/config.ts +7 -1
  81. package/templates/apps/web/lib/hub-session/entry.ts +238 -0
  82. package/templates/apps/web/lib/hub-session/index.ts +1 -4
  83. package/templates/apps/web/lib/hub-session/one-tap.tsx +148 -0
  84. package/templates/apps/web/lib/hub-session/session.ts +120 -2
  85. package/templates/apps/web/lib/hub-session/spoke-sign-in.tsx +277 -0
  86. package/templates/apps/web/lib/site-header.ts +14 -1
  87. package/templates/apps/web/lib/telemetry-scrub.ts +11 -0
  88. package/templates/apps/web/lib/topology.generated.ts +39 -0
  89. package/templates/apps/web/messages/en.json +112 -20
  90. package/templates/apps/web/middleware.ts +34 -2
  91. package/templates/apps/web/security-headers.config.ts +21 -0
  92. package/versions.json +47 -47
  93. package/templates/apps/web/app/[locale]/(authed)/sign-in-gate.tsx +0 -162
  94. package/templates/apps/web/components/signed-in-nav.tsx +0 -79
  95. package/templates/apps/web/lib/hub-session/__tests__/sign-in-gate.test.tsx +0 -180
  96. package/templates/apps/web/lib/hub-session/sign-in-gate.tsx +0 -162
@@ -16,10 +16,14 @@ import { render, screen } from "@testing-library/react";
16
16
  import userEvent from "@testing-library/user-event";
17
17
 
18
18
  const mockFetch = jest.fn();
19
+ const mockSocial = jest.fn();
19
20
  jest.mock("better-auth/react", () => ({
20
21
  __esModule: true,
21
22
  createAuthClient: () => ({
22
- signIn: { social: jest.fn(), email: jest.fn() },
23
+ signIn: {
24
+ social: (...args: unknown[]) => mockSocial(...args),
25
+ email: jest.fn(),
26
+ },
23
27
  $fetch: (...args: unknown[]) => mockFetch(...args),
24
28
  }),
25
29
  }));
@@ -59,8 +63,18 @@ async function requestLink(email = "member@example.com"): Promise<void> {
59
63
  await user.click(screen.getByTestId("auth-submit"));
60
64
  }
61
65
 
66
+ /** Clears every cookie jsdom holds, so each case starts with none. */
67
+ function clearCookies(): void {
68
+ for (const pair of document.cookie.split(";")) {
69
+ const name = pair.split("=")[0]?.trim();
70
+ if (name) document.cookie = `${name}=; Max-Age=0; Path=/`;
71
+ }
72
+ }
73
+
62
74
  beforeEach(() => {
63
75
  mockFetch.mockReset().mockResolvedValue({ data: { status: true }, error: null });
76
+ mockSocial.mockReset().mockResolvedValue({ data: {}, error: null });
77
+ clearCookies();
64
78
  });
65
79
 
66
80
  describe("SignInCard — email sign-in link (#7435)", () => {
@@ -157,3 +171,96 @@ describe("SignInCard — email sign-in link (#7435)", () => {
157
171
  expect(screen.getByText("Sign-in is not configured.")).toBeInTheDocument();
158
172
  });
159
173
  });
174
+
175
+ // #11095 AC-6 (D7): the card remembers the provider a person launched, and a
176
+ // returning person sees that one first, the rest behind "Use another way".
177
+ describe("SignInCard — the remembered method (#11095 D7)", () => {
178
+ const LABELS = {
179
+ emailLinkSubmit: "Email me a sign-in link",
180
+ ssoPrefix: "Sign in with",
181
+ google: "Google",
182
+ github: "GitHub",
183
+ };
184
+ const leadProps = (overrides: Partial<SignInCardProps> = {}) =>
185
+ props({
186
+ method: "password",
187
+ providers: ["google", "github"],
188
+ labels: LABELS,
189
+ continueWith: "Continue with",
190
+ useAnotherWay: "Use another way",
191
+ ...overrides,
192
+ });
193
+
194
+ it("writes the provider id before the provider launch is called", async () => {
195
+ const user = userEvent.setup();
196
+ let cookieAtLaunch = "";
197
+ mockSocial.mockImplementation(() => {
198
+ cookieAtLaunch = document.cookie;
199
+ return Promise.resolve({ data: {}, error: null });
200
+ });
201
+ render(<SignInCard {...leadProps()} />);
202
+ await user.click(screen.getByTestId("auth-social-google"));
203
+ expect(mockSocial).toHaveBeenCalledTimes(1);
204
+ expect(cookieAtLaunch).toContain("ailk-sign-in-method=google");
205
+ // It names the method only: no email, no user id, no time.
206
+ expect(document.cookie).toBe("ailk-sign-in-method=google");
207
+ });
208
+
209
+ it("an email-link request clears it", async () => {
210
+ document.cookie = "ailk-sign-in-method=google; Path=/";
211
+ render(<SignInCard {...leadProps({ method: "sso", providers: [] })} />);
212
+ await requestLink();
213
+ expect(document.cookie).not.toContain("ailk-sign-in-method");
214
+ });
215
+
216
+ it("with a remembered provider: one Continue with button first, no email field, and Use another way", () => {
217
+ render(<SignInCard {...leadProps({ remembered: "google" })} />);
218
+ const lead = screen.getByTestId("auth-sso-google");
219
+ expect(lead).toHaveTextContent("Continue with Google");
220
+ expect(screen.getAllByRole("button")[0]).toBe(lead);
221
+ expect(screen.queryByTestId("auth-sso-github")).toBeNull();
222
+ expect(screen.queryByTestId("auth-email")).toBeNull();
223
+ expect(screen.queryByTestId("auth-password")).toBeNull();
224
+ expect(screen.getByTestId("sign-in-use-another-way")).toHaveTextContent(
225
+ "Use another way",
226
+ );
227
+ });
228
+
229
+ it("Use another way restores the full card", async () => {
230
+ const user = userEvent.setup();
231
+ render(<SignInCard {...leadProps({ remembered: "google" })} />);
232
+ await user.click(screen.getByTestId("sign-in-use-another-way"));
233
+ expect(screen.getByTestId("auth-email")).toBeInTheDocument();
234
+ expect(screen.getByTestId("auth-social-google")).toBeInTheDocument();
235
+ expect(screen.getByTestId("auth-social-github")).toBeInTheDocument();
236
+ expect(screen.queryByTestId("auth-sso-google")).toBeNull();
237
+ expect(screen.queryByTestId("sign-in-use-another-way")).toBeNull();
238
+ });
239
+
240
+ it("the lead button launches its provider", async () => {
241
+ const user = userEvent.setup();
242
+ render(<SignInCard {...leadProps({ remembered: "google" })} />);
243
+ await user.click(screen.getByTestId("auth-sso-google"));
244
+ expect(mockSocial).toHaveBeenCalledTimes(1);
245
+ expect(document.cookie).toBe("ailk-sign-in-method=google");
246
+ });
247
+
248
+ it("a failed launch from the lead button shows the provider error", async () => {
249
+ const user = userEvent.setup();
250
+ mockSocial.mockRejectedValueOnce(new Error("boom"));
251
+ render(<SignInCard {...leadProps({ remembered: "google" })} />);
252
+ await user.click(screen.getByTestId("auth-sso-google"));
253
+ expect(await screen.findByTestId("sign-in-provider-error")).toBeInTheDocument();
254
+ });
255
+
256
+ it("with no remembered provider the card renders as today", () => {
257
+ const { container: today } = render(
258
+ <SignInCard {...props({ method: "password", providers: ["google"], labels: LABELS })} />,
259
+ );
260
+ const before = today.innerHTML;
261
+ today.remove();
262
+ const { container } = render(<SignInCard {...leadProps({ providers: ["google"] })} />);
263
+ expect(container.innerHTML).toBe(before);
264
+ expect(screen.queryByTestId("sign-in-use-another-way")).toBeNull();
265
+ });
266
+ });
@@ -28,14 +28,23 @@
28
28
  * so a buyer who switches to sign-up keeps the destination; a refused or
29
29
  * absent `next` gives the bare `/sign-up`.
30
30
  *
31
- * Signed-in visitors are not redirected here — the Nav's session-aware action
32
- * cluster (Account / Sign out) is the affordance for them.
31
+ * Signed-in visitors are not redirected here — the Nav's "Your account" link
32
+ * is the affordance for them (#11095 D6).
33
+ *
34
+ * Remembered method (#11095 D7): the `ailk-sign-in-method` cookie, read here
35
+ * and parsed against the active providers (`remembered-method.ts`), lets the
36
+ * card lead with the provider the person last launched. A value that does
37
+ * not parse is today's render.
38
+ *
39
+ * The spoke back link goes to the spoke's home (#11095 D5): its `/account`
40
+ * would start the hub sign-in again.
33
41
  */
34
42
 
35
43
  import { hubSignIn } from "@working-theory/api-client";
36
44
  import { localeHref } from "@working-theory/ui";
37
45
  import { accountEmailHintSchema } from "@working-theory/validation";
38
46
  import type { Metadata } from "next";
47
+ import { cookies } from "next/headers";
39
48
  import { getTranslations } from "next-intl/server";
40
49
  import type { ReactElement } from "react";
41
50
 
@@ -51,6 +60,10 @@ import {
51
60
  import { legalFootnote } from "../legal-footnote";
52
61
 
53
62
  import { hrefWithNext, resolveNextPath } from "./next-path";
63
+ import {
64
+ REMEMBERED_METHOD_COOKIE,
65
+ parseRememberedMethod,
66
+ } from "./remembered-method";
54
67
  import { SignInCard, type SignInProvider } from "./sign-in-card";
55
68
  import { resolveSignInCardText, type SignInCardText } from "./sign-in-text";
56
69
 
@@ -94,6 +107,18 @@ function linkNoticeFor(
94
107
  : text.errorLabels.signInFailed;
95
108
  }
96
109
 
110
+ /**
111
+ * #11095 D7 — the raw remembered-method cookie. A read that throws (no
112
+ * request scope) is no cookie, so the card renders as today.
113
+ */
114
+ async function rememberedCookie(): Promise<string | undefined> {
115
+ try {
116
+ return (await cookies()).get(REMEMBERED_METHOD_COOKIE)?.value;
117
+ } catch {
118
+ return undefined;
119
+ }
120
+ }
121
+
97
122
  export async function generateMetadata({ params }: Props): Promise<Metadata> {
98
123
  const { locale } = await params;
99
124
  const t = await getTranslations({ locale, namespace: "signIn" });
@@ -156,6 +181,7 @@ export default async function SignInPage({
156
181
  // Only the email link produces `?error=` here; with it off, today's render.
157
182
  const linkNotice = emailLink ? linkNoticeFor(error, text) : undefined;
158
183
  const defaultEmail = hintedEmail(rawEmail);
184
+ const remembered = parseRememberedMethod(await rememberedCookie(), providers);
159
185
 
160
186
  const spoke = await spokeFromNext(next);
161
187
  const t = await getTranslations({ locale, namespace: "signIn" });
@@ -165,7 +191,7 @@ export default async function SignInPage({
165
191
  {...(spoke
166
192
  ? {
167
193
  backLink: {
168
- href: `${spoke.origin}/account`,
194
+ href: `${spoke.origin}/`,
169
195
  label: t("backTo", { site: spoke.name }),
170
196
  },
171
197
  }
@@ -196,6 +222,13 @@ export default async function SignInPage({
196
222
  {...(linkNotice !== undefined ? { linkNotice } : {})}
197
223
  {...(defaultEmail !== undefined ? { defaultEmail } : {})}
198
224
  emailLinkLabels={text.emailLinkLabels}
225
+ {...(remembered !== undefined
226
+ ? {
227
+ remembered,
228
+ continueWith: text.continueWith,
229
+ useAnotherWay: text.useAnotherWay,
230
+ }
231
+ : {})}
199
232
  />
200
233
  );
201
234
  }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * The remembered sign-in method (#11095 D7): one cookie naming the provider a
3
+ * person last launched on this card, so a returning person sees that one
4
+ * first. It names the method only — one of `google` or `github`, never an
5
+ * email, a user id or a time — and only reorders the card: it never changes
6
+ * who may sign in. An email method clears it, because the card already leads
7
+ * with the email field.
8
+ */
9
+
10
+ import type { SignInProvider } from "./sign-in-card";
11
+
12
+ export const REMEMBERED_METHOD_COOKIE = "ailk-sign-in-method";
13
+
14
+ /** One year, in seconds. */
15
+ const MAX_AGE_SECONDS = 31_536_000;
16
+
17
+ /**
18
+ * The remembered provider, only when the raw value is exactly `google` or
19
+ * `github` and is one of the page's active `providers`; otherwise `undefined`.
20
+ */
21
+ export function parseRememberedMethod(
22
+ raw: string | undefined,
23
+ providers: readonly SignInProvider[],
24
+ ): SignInProvider | undefined {
25
+ if (raw !== "google" && raw !== "github") return undefined;
26
+ return providers.includes(raw) ? raw : undefined;
27
+ }
28
+
29
+ /** Browser only: remember `provider`, or clear the cookie with `null`. */
30
+ export function rememberMethod(provider: SignInProvider | null): void {
31
+ if (typeof document === "undefined") return;
32
+ const secure = window.location.protocol === "https:" ? "; Secure" : "";
33
+ document.cookie =
34
+ provider === null
35
+ ? `${REMEMBERED_METHOD_COOKIE}=; Path=/; Max-Age=0; SameSite=Lax${secure}`
36
+ : `${REMEMBERED_METHOD_COOKIE}=${provider}; Path=/; Max-Age=${MAX_AGE_SECONDS}; SameSite=Lax${secure}`;
37
+ }
@@ -6,8 +6,8 @@
6
6
  * Composes the shipped `AuthCard` block (`intent="sign-in"`, `footer="none"`)
7
7
  * and wires its provider buttons / password form to the Better Auth client
8
8
  * via the shared `useAuthCardFlow` hook (#6018 AC-3) — the same hook
9
- * `SignUpCard` next door uses, using the SAME `createAuthClient()` idiom the
10
- * `(authed)` group's `SignInGate` uses. The page (RSC) decides providers +
9
+ * `SignUpCard` next door uses, through its one module-scope
10
+ * `createAuthClient()`. The page (RSC) decides providers +
11
11
  * method from auth-env and hands them in; this component never reads env
12
12
  * itself.
13
13
  *
@@ -43,12 +43,18 @@
43
43
  * `magicLinkClient()` plugin, so no ESM-only module enters the client graph
44
44
  * every `(auth)` and `(authed)` suite would then have to mock. The answer is
45
45
  * the same for an address with and without an account, so a success swaps to
46
- * a sent state that never names the address. The gate composes this card too
47
- * (`(authed)/sign-in-gate.tsx`).
46
+ * a sent state that never names the address.
48
47
  *
49
48
  * Hinted email (#8757 D9): the page hands in `defaultEmail` (already checked
50
49
  * by `accountEmailHintSchema`); it reaches AuthCard as the starting value of
51
50
  * every email input. Absent → AuthCard's render is unchanged.
51
+ *
52
+ * Remembered method (#11095 D7): a provider launch writes its id to the
53
+ * `ailk-sign-in-method` cookie (`remembered-method.ts`) before the launch; a
54
+ * password submit or a sign-in-link request clears it. With `remembered` set
55
+ * the card leads with that one provider ("Continue with Google", the SSO
56
+ * stack's 44px button) and "Use another way" restores the full card. Absent,
57
+ * the render is today's.
52
58
  */
53
59
 
54
60
  import {
@@ -57,11 +63,13 @@ import {
57
63
  type AuthCardLabels,
58
64
  type AuthSubmitData,
59
65
  } from "@working-theory/ui/blocks";
60
- import { Alert, AlertDescription } from "@working-theory/ui/primitives";
66
+ import { Alert, AlertDescription, Button } from "@working-theory/ui/primitives";
61
67
  import { useRef, useState, type ReactElement, type ReactNode } from "react";
62
68
 
63
69
  import { authClient, useAuthCardFlow } from "../use-auth-card-flow";
64
70
 
71
+ import { rememberMethod } from "./remembered-method";
72
+
65
73
  /** The OAuth providers this page can launch — a subset of AuthCard's. */
66
74
  export type SignInProvider = "google" | "github";
67
75
 
@@ -113,6 +121,12 @@ export interface SignInCardProps {
113
121
  prospect?: { prompt: string; linkLabel: string; href: string };
114
122
  /** The acknowledgement sentence(s) at the card's foot (#8790 D6). */
115
123
  footnote?: ReactNode;
124
+ /** #11095 D7 — the provider the person last launched, already parsed by the page. */
125
+ remembered?: SignInProvider;
126
+ /** The lead button's prefix in place of `labels.ssoPrefix` ("Continue with"). */
127
+ continueWith?: string;
128
+ /** The control under the lead card that shows every method ("Use another way"). */
129
+ useAnotherWay?: string;
116
130
  }
117
131
 
118
132
  export function SignInCard({
@@ -134,6 +148,9 @@ export function SignInCard({
134
148
  backLink,
135
149
  prospect,
136
150
  footnote,
151
+ remembered,
152
+ continueWith,
153
+ useAnotherWay,
137
154
  }: SignInCardProps): ReactElement {
138
155
  const { errors, providerError, launchProvider, submitPassword } =
139
156
  useAuthCardFlow(next, {
@@ -145,6 +162,8 @@ export function SignInCard({
145
162
  // One request at a time: a double-click would spend two of the per-IP and
146
163
  // per-address sends and mint two live tokens (code review).
147
164
  const emailLinkPending = useRef(false);
165
+ const [expanded, setExpanded] = useState(false);
166
+ const lead = remembered !== undefined && !expanded;
148
167
 
149
168
  const notConfigured =
150
169
  method === "sso" && providers.length === 0 && !emailLink;
@@ -155,12 +174,17 @@ export function SignInCard({
155
174
  ...(method === "password" ? (["password"] as const) : []),
156
175
  ];
157
176
 
177
+ const launch = (provider: SignInProvider): void => {
178
+ rememberMethod(provider);
179
+ void launchProvider(provider);
180
+ };
158
181
  const providerButtons = providers.map((provider) => ({
159
182
  provider,
160
- onClick: () => void launchProvider(provider),
183
+ onClick: () => launch(provider),
161
184
  }));
162
185
 
163
186
  const handleSubmit = (data: AuthSubmitData): void => {
187
+ rememberMethod(null);
164
188
  void submitPassword(
165
189
  authClient.signIn.email({
166
190
  email: data.email,
@@ -173,6 +197,7 @@ export function SignInCard({
173
197
  const requestEmailLink = async (email: string): Promise<void> => {
174
198
  if (emailLinkPending.current) return;
175
199
  emailLinkPending.current = true;
200
+ rememberMethod(null);
176
201
  setEmailLinkError(null);
177
202
  try {
178
203
  const { error } = await authClient.$fetch("/sign-in/magic-link", {
@@ -225,7 +250,7 @@ export function SignInCard({
225
250
  */
226
251
  <div className="flex flex-col gap-4" data-testid="sign-in-page">
227
252
  {backLink ? <AuthBackLink href={backLink.href} label={backLink.label} /> : null}
228
- {method === "sso" && providerError ? (
253
+ {(method === "sso" || lead) && providerError ? (
229
254
  <Alert variant="error" data-testid="sign-in-provider-error">
230
255
  <AlertDescription>{providerError}</AlertDescription>
231
256
  </Alert>
@@ -235,32 +260,64 @@ export function SignInCard({
235
260
  <AlertDescription>{linkNotice}</AlertDescription>
236
261
  </Alert>
237
262
  ) : null}
238
- <AuthCard
239
- intent="sign-in"
240
- method={method}
241
- footer="none"
242
- {...(logo !== undefined ? { logo } : {})}
243
- {...(forgotHref !== undefined ? { forgotHref } : {})}
244
- {...(forgot !== undefined ? { forgot } : {})}
245
- // The heading stands alone (#8790 D3): no subhead unless the card
246
- // is inert and must say why.
247
- subhead={notConfigured ? notConfiguredSubhead : ""}
248
- {...(prospect !== undefined ? { prospect } : {})}
249
- {...(footnote !== undefined ? { footnote } : {})}
250
- providers={providerButtons}
251
- onSubmit={handleSubmit}
252
- errors={
253
- emailLinkError ? { ...errors, emailLink: emailLinkError } : errors
254
- }
255
- labels={labels}
256
- {...(defaultEmail !== undefined ? { defaultEmail } : {})}
257
- {...(methods.length > 0 ? { methodSwitch: { methods } } : {})}
258
- {...(emailLink
259
- ? {
260
- onEmailLink: (email: string) => void requestEmailLink(email),
261
- }
262
- : {})}
263
- />
263
+ {lead ? (
264
+ <>
265
+ <AuthCard
266
+ intent="sign-in"
267
+ method="sso"
268
+ footer="none"
269
+ {...(logo !== undefined ? { logo } : {})}
270
+ subhead=""
271
+ {...(prospect !== undefined ? { prospect } : {})}
272
+ {...(footnote !== undefined ? { footnote } : {})}
273
+ providers={[
274
+ { provider: remembered, onClick: () => launch(remembered) },
275
+ ]}
276
+ labels={{
277
+ ...labels,
278
+ ...(continueWith !== undefined
279
+ ? { ssoPrefix: continueWith }
280
+ : {}),
281
+ }}
282
+ />
283
+ <Button
284
+ variant="ghost"
285
+ size="big"
286
+ type="button"
287
+ onClick={() => setExpanded(true)}
288
+ data-testid="sign-in-use-another-way"
289
+ >
290
+ {useAnotherWay}
291
+ </Button>
292
+ </>
293
+ ) : (
294
+ <AuthCard
295
+ intent="sign-in"
296
+ method={method}
297
+ footer="none"
298
+ {...(logo !== undefined ? { logo } : {})}
299
+ {...(forgotHref !== undefined ? { forgotHref } : {})}
300
+ {...(forgot !== undefined ? { forgot } : {})}
301
+ // The heading stands alone (#8790 D3): no subhead unless the card
302
+ // is inert and must say why.
303
+ subhead={notConfigured ? notConfiguredSubhead : ""}
304
+ {...(prospect !== undefined ? { prospect } : {})}
305
+ {...(footnote !== undefined ? { footnote } : {})}
306
+ providers={providerButtons}
307
+ onSubmit={handleSubmit}
308
+ errors={
309
+ emailLinkError ? { ...errors, emailLink: emailLinkError } : errors
310
+ }
311
+ labels={labels}
312
+ {...(defaultEmail !== undefined ? { defaultEmail } : {})}
313
+ {...(methods.length > 0 ? { methodSwitch: { methods } } : {})}
314
+ {...(emailLink
315
+ ? {
316
+ onEmailLink: (email: string) => void requestEmailLink(email),
317
+ }
318
+ : {})}
319
+ />
320
+ )}
264
321
  </div>
265
322
  );
266
323
  }
@@ -1,15 +1,14 @@
1
1
  /**
2
2
  * The `SignInCard`'s translated copy, resolved on the server (#7435 § D9).
3
3
  *
4
- * One helper so `/sign-in` and the `(authed)` gate render the SAME labels from
5
- * the same `signIn` keys — the gate composes `SignInCard` when the email
6
- * sign-in link is on, and a second copy of this object would drift.
4
+ * One helper, so every `SignInCard` renders the SAME labels from the same
5
+ * `signIn` keys — a second copy of this object would drift.
7
6
  *
8
7
  * The heading names the site — "Sign in to <site>" (#9662) — from
9
8
  * `SITE_NAME`, the deployment's own display name (env, else `_site.mdx`),
10
9
  * never from the request.
11
10
  *
12
- * Plain data only: the gate hands this object to a client component, and a
11
+ * Plain data only: the page hands this object to a client component, and a
13
12
  * function cannot cross that boundary (`/sign-in` resolves its "Back to
14
13
  * <spoke>" line itself).
15
14
  */
@@ -39,6 +38,10 @@ export interface SignInCardText {
39
38
  emailLinkLabels: SignInEmailLinkLabels;
40
39
  /** The notice for a link that failed verification (`?error=INVALID_TOKEN`). */
41
40
  emailLinkExpired: string;
41
+ /** #11095 D7 — the remembered provider's button prefix ("Continue with"). */
42
+ continueWith: string;
43
+ /** #11095 D7 — the control that shows every method ("Use another way"). */
44
+ useAnotherWay: string;
42
45
  }
43
46
 
44
47
  export async function resolveSignInCardText(
@@ -84,5 +87,7 @@ export async function resolveSignInCardText(
84
87
  rateLimited: t("emailLinkRateLimited"),
85
88
  },
86
89
  emailLinkExpired: t("emailLinkExpired"),
90
+ continueWith: t("continueWith"),
91
+ useAnotherWay: t("useAnotherWay"),
87
92
  };
88
93
  }