create-ailk 0.35.1 → 0.37.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.
- package/README.md +1 -1
- package/component-catalog.json +51 -1
- package/component-catalog.md +8 -5
- package/dist/lib/env-catalog.js +8 -0
- package/dist/surfaces.js +66 -22
- package/dist/topology.d.ts +4 -4
- package/dist/topology.js +104 -60
- package/dist/update.d.ts +19 -1
- package/dist/update.js +293 -35
- package/package.json +3 -3
- package/templates/.env.example +38 -0
- package/templates/apps/api/.env.example +45 -0
- package/templates/apps/api/CLAUDE.md +12 -4
- package/templates/apps/api/src/lib/__mocks__/prisma.ts +7 -0
- package/templates/apps/mcp/CLAUDE.md +4 -2
- package/templates/apps/web/.env.example +16 -0
- package/templates/apps/web/CLAUDE.md +73 -5
- package/templates/apps/web/app/[locale]/(auth)/__tests__/password-reset.test.tsx +2 -0
- package/templates/apps/web/app/[locale]/(auth)/reset-password/__tests__/return.test.tsx +179 -0
- package/templates/apps/web/app/[locale]/(auth)/reset-password/page.tsx +22 -2
- package/templates/apps/web/app/[locale]/(auth)/reset-password/reset-password-card.tsx +9 -2
- package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/page.test.tsx +52 -1
- package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/remembered-method.test.ts +43 -0
- package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/sign-in-card.test.tsx +108 -1
- package/templates/apps/web/app/[locale]/(auth)/sign-in/page.tsx +36 -3
- package/templates/apps/web/app/[locale]/(auth)/sign-in/remembered-method.ts +37 -0
- package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-card.tsx +90 -33
- package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-text.ts +9 -4
- package/templates/apps/web/app/[locale]/(authed)/__tests__/gate.test.tsx +79 -348
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +241 -66
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/general.test.tsx +242 -28
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +377 -151
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +26 -1
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout-sign-out.test.tsx +10 -5
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +17 -6
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +51 -12
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-popups.test.tsx +17 -2
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/notifications.test.tsx +153 -2
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +206 -23
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/popups.test.tsx +150 -188
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +235 -177
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/rich-translator.ts +63 -0
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/security.test.tsx +0 -3
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/thread.test.tsx +340 -0
- package/templates/apps/web/app/[locale]/(authed)/account/account-data.ts +7 -5
- package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +20 -4
- package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +8 -4
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +161 -0
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/__tests__/page.test.tsx +426 -0
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/appointments-data.ts +76 -0
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +139 -0
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +92 -24
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +32 -1
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/file-route.test.ts +76 -3
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/page.test.tsx +290 -41
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-data.ts +109 -11
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +43 -44
- package/templates/apps/web/app/[locale]/(authed)/account/billing/__tests__/offerings.test.ts +99 -0
- package/templates/apps/web/app/[locale]/(authed)/account/billing/offerings.ts +123 -0
- package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +323 -73
- package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +199 -43
- package/templates/apps/web/app/[locale]/(authed)/account/components/request-quote.tsx +52 -7
- package/templates/apps/web/app/[locale]/(authed)/account/connect/__tests__/page.test.tsx +8 -1
- package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +7 -3
- package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/phone-verification.test.tsx +215 -0
- package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/seam-imports.test.ts +65 -0
- package/templates/apps/web/app/[locale]/(authed)/account/general/account-name.ts +36 -0
- package/templates/apps/web/app/[locale]/(authed)/account/general/contact-actions.ts +70 -2
- package/templates/apps/web/app/[locale]/(authed)/account/general/contact-details.tsx +42 -0
- package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +97 -53
- package/templates/apps/web/app/[locale]/(authed)/account/general/phone-actions.ts +122 -0
- package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +215 -0
- package/templates/apps/web/app/[locale]/(authed)/account/general/photo-actions.ts +73 -0
- package/templates/apps/web/app/[locale]/(authed)/account/general/profile-form.tsx +12 -9
- package/templates/apps/web/app/[locale]/(authed)/account/general/profile-source.ts +18 -4
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +20 -2
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/member-thread-composer.tsx +43 -0
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +125 -0
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-data.ts +88 -0
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-write.ts +31 -0
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/invitation-id.test.ts +35 -0
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/page.test.tsx +266 -0
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/actions.ts +116 -0
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/invitation-id.ts +12 -0
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +154 -0
- package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +9 -6
- package/templates/apps/web/app/[locale]/(authed)/account/new-menu.tsx +33 -8
- package/templates/apps/web/app/[locale]/(authed)/account/new-popups.tsx +31 -52
- package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +44 -4
- package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +69 -49
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/__tests__/export-route.test.ts +173 -0
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/actions.ts +42 -4
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +102 -0
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +147 -137
- package/templates/apps/web/app/[locale]/(authed)/account/security/__tests__/hub-variant.test.tsx +258 -0
- package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +21 -22
- package/templates/apps/web/app/[locale]/(authed)/account/security/security-panel.tsx +34 -6
- package/templates/apps/web/app/[locale]/(authed)/account/security/security-source.ts +37 -7
- package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +0 -2
- package/templates/apps/web/app/[locale]/(authed)/account/settings-frame.tsx +8 -5
- package/templates/apps/web/app/[locale]/(authed)/layout.tsx +15 -13
- package/templates/apps/web/app/[locale]/(authed)/signed-out-gate.generated.tsx +20 -52
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +3 -2
- package/templates/apps/web/app/[locale]/layout.tsx +24 -75
- package/templates/apps/web/app/[locale]/purchase/__tests__/success.test.tsx +50 -0
- package/templates/apps/web/app/[locale]/purchase/success/page.tsx +48 -7
- package/templates/apps/web/app/api/auth/hub/__tests__/entry-routes.test.ts +749 -0
- package/templates/apps/web/app/api/auth/hub/authorize/__tests__/route.test.ts +166 -7
- package/templates/apps/web/app/api/auth/hub/authorize/route.ts +96 -30
- package/templates/apps/web/app/api/auth/hub/continuation.ts +51 -2
- package/templates/apps/web/app/api/auth/hub/email/route.ts +111 -0
- package/templates/apps/web/app/api/auth/hub/entry-shared.ts +163 -0
- package/templates/apps/web/app/api/auth/hub/password/__tests__/return.test.ts +86 -0
- package/templates/apps/web/app/api/auth/hub/password/__tests__/route.test.ts +368 -0
- package/templates/apps/web/app/api/auth/hub/password/return.ts +86 -0
- package/templates/apps/web/app/api/auth/hub/password/route.ts +171 -0
- package/templates/apps/web/app/api/auth/hub/purchase/route.ts +230 -0
- package/templates/apps/web/app/api/auth/hub/purchase-link/route.ts +174 -0
- package/templates/apps/web/app/api/auth/hub/sign-up/route.ts +60 -0
- package/templates/apps/web/app/api/auth/hub/sign-up-evidence.ts +97 -0
- package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +738 -7
- package/templates/apps/web/app/api/hub-session/callback/route.ts +13 -47
- package/templates/apps/web/app/api/hub-session/email/route.ts +125 -0
- package/templates/apps/web/app/api/hub-session/one-tap/nonce/route.ts +49 -0
- package/templates/apps/web/app/api/hub-session/one-tap/route.ts +106 -0
- package/templates/apps/web/app/api/hub-session/open/route.ts +111 -0
- package/templates/apps/web/app/api/hub-session/password/return/route.ts +69 -0
- package/templates/apps/web/app/api/hub-session/password/route.ts +106 -0
- package/templates/apps/web/app/api/hub-session/sign-in/route.ts +23 -40
- package/templates/apps/web/app/api/hub-session/sign-out/route.ts +1 -10
- package/templates/apps/web/auth.ts +133 -6
- package/templates/apps/web/components/sign-out-trigger.tsx +1 -1
- package/templates/apps/web/lib/__tests__/account-config.test.ts +129 -1
- package/templates/apps/web/lib/__tests__/auth-email.test.ts +141 -0
- package/templates/apps/web/lib/__tests__/auth-phone.test.ts +445 -0
- package/templates/apps/web/lib/__tests__/auth-sms.test.ts +140 -0
- package/templates/apps/web/lib/__tests__/fixtures/tsconfig.flow.json +18 -0
- package/templates/apps/web/lib/__tests__/offerings-pricing.test.ts +33 -0
- package/templates/apps/web/lib/__tests__/site-header.test.ts +13 -0
- package/templates/apps/web/lib/__tests__/telemetry-scrub.test.ts +19 -1
- package/templates/apps/web/lib/account-config.ts +132 -8
- package/templates/apps/web/lib/auth-email.ts +62 -6
- package/templates/apps/web/lib/auth-env.ts +13 -0
- package/templates/apps/web/lib/auth-routes.ts +11 -6
- package/templates/apps/web/lib/auth-sms.ts +180 -0
- package/templates/apps/web/lib/hub-session/__tests__/hub-session.test.ts +28 -0
- package/templates/apps/web/lib/hub-session/__tests__/spoke-sign-in.test.tsx +332 -0
- package/templates/apps/web/lib/hub-session/config.ts +7 -1
- package/templates/apps/web/lib/hub-session/entry.ts +238 -0
- package/templates/apps/web/lib/hub-session/index.ts +1 -4
- package/templates/apps/web/lib/hub-session/one-tap.tsx +148 -0
- package/templates/apps/web/lib/hub-session/session.ts +120 -2
- package/templates/apps/web/lib/hub-session/spoke-sign-in.tsx +277 -0
- package/templates/apps/web/lib/offerings-pricing.ts +4 -1
- package/templates/apps/web/lib/site-header.ts +14 -1
- package/templates/apps/web/lib/telemetry-scrub.ts +11 -0
- package/templates/apps/web/lib/topology.generated.ts +39 -0
- package/templates/apps/web/messages/en.json +264 -96
- package/templates/apps/web/middleware.ts +34 -2
- package/templates/apps/web/security-headers.config.ts +21 -0
- package/versions.json +48 -48
- package/templates/apps/web/app/[locale]/(authed)/account/components/schedule-service.tsx +0 -276
- package/templates/apps/web/app/[locale]/(authed)/account/components/send-message.tsx +0 -128
- package/templates/apps/web/app/[locale]/(authed)/account/settings/__tests__/theme-modes.test.ts +0 -42
- package/templates/apps/web/app/[locale]/(authed)/account/settings/theme-modes.ts +0 -40
- package/templates/apps/web/app/[locale]/(authed)/sign-in-gate.tsx +0 -162
- package/templates/apps/web/components/signed-in-nav.tsx +0 -79
- package/templates/apps/web/lib/hub-session/__tests__/sign-in-gate.test.tsx +0 -180
- package/templates/apps/web/lib/hub-session/sign-in-gate.tsx +0 -162
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `/reset-password` returns a spoke's person to their Security tab (#11162
|
|
3
|
+
* AC-2).
|
|
4
|
+
*
|
|
5
|
+
* The page's decision is under test — which `completeHref`, if any, it hands
|
|
6
|
+
* the island for a `?ref=` — so the island is a double that records its
|
|
7
|
+
* props; its own navigation is pinned below with the real card and an
|
|
8
|
+
* injected `navigate`, the sibling `password-reset.test.tsx`'s idiom.
|
|
9
|
+
*/
|
|
10
|
+
import { render, screen, waitFor } from "@testing-library/react";
|
|
11
|
+
import userEvent from "@testing-library/user-event";
|
|
12
|
+
|
|
13
|
+
const mockResetSendConfigured = jest.fn();
|
|
14
|
+
// eslint-disable-next-line no-restricted-syntax -- #507: auth-env.ts is a pure env-introspection module with no external boundary to mock instead.
|
|
15
|
+
jest.mock("../../../../../lib/auth-env", () => ({
|
|
16
|
+
__esModule: true,
|
|
17
|
+
getActiveProviderIds: () => ["email"],
|
|
18
|
+
isSignUpOpen: () => false,
|
|
19
|
+
isResetAvailable: () => mockResetSendConfigured(),
|
|
20
|
+
resetSendConfigured: () => mockResetSendConfigured(),
|
|
21
|
+
phoneVerificationConfigured: () => false,
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
const mockResetPassword = jest.fn();
|
|
25
|
+
jest.mock("better-auth/react", () => ({
|
|
26
|
+
__esModule: true,
|
|
27
|
+
createAuthClient: () => ({
|
|
28
|
+
resetPassword: (...args: unknown[]) => mockResetPassword(...args),
|
|
29
|
+
}),
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
const mockCard = jest.fn();
|
|
33
|
+
// eslint-disable-next-line no-restricted-syntax -- #507: the island's post-reset navigation is `window.location.assign`, which jsdom cannot observe; the page's one decision — the `completeHref` it hands the island — is read from the island's props, and the real island is pinned below with an injected `navigate`.
|
|
34
|
+
jest.mock("../reset-password-card", () => ({
|
|
35
|
+
__esModule: true,
|
|
36
|
+
ResetPasswordCard: (props: Record<string, unknown>) => {
|
|
37
|
+
mockCard(props);
|
|
38
|
+
return <div data-testid="reset-card-double" />;
|
|
39
|
+
},
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
import en from "../../../../../messages/en.json";
|
|
43
|
+
import { mintSecurityReturn } from "../../../../api/auth/hub/password/return";
|
|
44
|
+
import ResetPasswordPage from "../page";
|
|
45
|
+
|
|
46
|
+
const { ResetPasswordCard } = jest.requireActual<typeof import("../reset-password-card")>(
|
|
47
|
+
"../reset-password-card",
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const SECRET = "s".repeat(43);
|
|
51
|
+
const SPOKE = "https://spoke.example";
|
|
52
|
+
/** The spoke's return route, which drops the revoked session before the tab (#11162). */
|
|
53
|
+
const LANDING = `${SPOKE}/api/hub-session/password/return?next=${encodeURIComponent("/account/security")}`;
|
|
54
|
+
const ORIGINAL_ENV = process.env;
|
|
55
|
+
|
|
56
|
+
beforeEach(() => {
|
|
57
|
+
jest.clearAllMocks();
|
|
58
|
+
process.env = { ...ORIGINAL_ENV, BETTER_AUTH_SECRET: SECRET, BETTER_AUTH_URL: "https://hub.example/api/auth" };
|
|
59
|
+
mockResetSendConfigured.mockReturnValue(true);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
afterAll(() => {
|
|
63
|
+
process.env = ORIGINAL_ENV;
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
async function renderPage(query: Record<string, string>): Promise<void> {
|
|
67
|
+
render(
|
|
68
|
+
await ResetPasswordPage({
|
|
69
|
+
params: Promise.resolve({ locale: "en" }),
|
|
70
|
+
searchParams: Promise.resolve(query),
|
|
71
|
+
}),
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The props the page handed the island. */
|
|
76
|
+
function cardProps(): Record<string, unknown> {
|
|
77
|
+
expect(mockCard).toHaveBeenCalledTimes(1);
|
|
78
|
+
return mockCard.mock.calls[0]?.[0] as Record<string, unknown>;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
describe("the page's return decision", () => {
|
|
82
|
+
it("a ref the hub sealed sends a completed reset to the spoke's return route, bound for its Security tab", async () => {
|
|
83
|
+
const ref = mintSecurityReturn(SPOKE, "/account/security", SECRET);
|
|
84
|
+
await renderPage({ token: "tok_live", ref });
|
|
85
|
+
expect(cardProps()).toMatchObject({
|
|
86
|
+
token: "tok_live",
|
|
87
|
+
signInHref: "/sign-in",
|
|
88
|
+
completeHref: LANDING,
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it.each([
|
|
93
|
+
["no ref", {}],
|
|
94
|
+
["a ref sealed under another secret", { ref: mintSecurityReturn(SPOKE, "/account/security", "x".repeat(43)) }],
|
|
95
|
+
["a ref that is not one", { ref: "https://evil.example/account/security" }],
|
|
96
|
+
["an expired ref", { ref: mintSecurityReturn(SPOKE, "/account/security", SECRET, Date.now() - 5_000_000) }],
|
|
97
|
+
] as Array<[string, Record<string, string>]>)("%s leaves the completed reset on the hub's sign-in", async (_label, query) => {
|
|
98
|
+
await renderPage({ token: "tok_live", ...query });
|
|
99
|
+
const props = cardProps();
|
|
100
|
+
expect(props.signInHref).toBe("/sign-in");
|
|
101
|
+
expect(props).not.toHaveProperty("completeHref");
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("a repeated ref reads as its first value only", async () => {
|
|
105
|
+
const ref = mintSecurityReturn(SPOKE, "/account/security", SECRET);
|
|
106
|
+
render(
|
|
107
|
+
await ResetPasswordPage({
|
|
108
|
+
params: Promise.resolve({ locale: "en" }),
|
|
109
|
+
searchParams: Promise.resolve({ token: "tok_live", ref: [ref, "second"] }),
|
|
110
|
+
}),
|
|
111
|
+
);
|
|
112
|
+
expect(cardProps()).toMatchObject({ completeHref: LANDING });
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("the expired-token state ignores the ref and renders no island", async () => {
|
|
116
|
+
const ref = mintSecurityReturn(SPOKE, "/account/security", SECRET);
|
|
117
|
+
await renderPage({ error: "INVALID_TOKEN", ref });
|
|
118
|
+
expect(screen.getByTestId("reset-token-error")).toBeInTheDocument();
|
|
119
|
+
expect(mockCard).not.toHaveBeenCalled();
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
describe("the island honours completeHref", () => {
|
|
124
|
+
const labels = {
|
|
125
|
+
resetHeading: en.auth.resetHeading,
|
|
126
|
+
resetSubmit: en.auth.resetSubmit,
|
|
127
|
+
newPassword: en.auth.newPassword,
|
|
128
|
+
confirmPassword: en.auth.confirmPassword,
|
|
129
|
+
backToSignIn: en.auth.backToSignIn,
|
|
130
|
+
};
|
|
131
|
+
const errorLabels = {
|
|
132
|
+
resetFailed: en.auth.resetFailed,
|
|
133
|
+
invalidToken: en.auth.resetExpiredSubhead,
|
|
134
|
+
mismatch: en.auth.passwordMismatch,
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
async function submit(): Promise<void> {
|
|
138
|
+
const user = userEvent.setup();
|
|
139
|
+
await user.type(screen.getByTestId("auth-password"), "a-long-enough-pw");
|
|
140
|
+
await user.type(screen.getByTestId("auth-confirm-password"), "a-long-enough-pw");
|
|
141
|
+
await user.click(screen.getByTestId("auth-submit"));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
it("a completed reset lands on the spoke's return route, and the back link stays the hub's sign-in", async () => {
|
|
145
|
+
mockResetPassword.mockResolvedValue({});
|
|
146
|
+
const navigate = jest.fn();
|
|
147
|
+
render(
|
|
148
|
+
<ResetPasswordCard
|
|
149
|
+
token="tok_live"
|
|
150
|
+
signInHref="/sign-in"
|
|
151
|
+
completeHref={LANDING}
|
|
152
|
+
labels={labels}
|
|
153
|
+
errorLabels={errorLabels}
|
|
154
|
+
navigate={navigate}
|
|
155
|
+
/>,
|
|
156
|
+
);
|
|
157
|
+
expect(screen.getByRole("link", { name: en.auth.backToSignIn })).toHaveAttribute("href", "/sign-in");
|
|
158
|
+
await submit();
|
|
159
|
+
await waitFor(() => expect(navigate).toHaveBeenCalledWith(LANDING));
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("a failed reset navigates nowhere", async () => {
|
|
163
|
+
mockResetPassword.mockResolvedValue({ error: { message: "nope" } });
|
|
164
|
+
const navigate = jest.fn();
|
|
165
|
+
render(
|
|
166
|
+
<ResetPasswordCard
|
|
167
|
+
token="tok_live"
|
|
168
|
+
signInHref="/sign-in"
|
|
169
|
+
completeHref={LANDING}
|
|
170
|
+
labels={labels}
|
|
171
|
+
errorLabels={errorLabels}
|
|
172
|
+
navigate={navigate}
|
|
173
|
+
/>,
|
|
174
|
+
);
|
|
175
|
+
await submit();
|
|
176
|
+
await waitFor(() => expect(mockResetPassword).toHaveBeenCalled());
|
|
177
|
+
expect(navigate).not.toHaveBeenCalled();
|
|
178
|
+
});
|
|
179
|
+
});
|
|
@@ -28,6 +28,15 @@
|
|
|
28
28
|
* The token is read from `searchParams` and handed to the island as a prop. It
|
|
29
29
|
* is the credential, so nothing here logs it and nothing re-appends it to a
|
|
30
30
|
* URL.
|
|
31
|
+
*
|
|
32
|
+
* `?ref=` (#11162) is the sealed return of a link the hub mailed for a
|
|
33
|
+
* spoke's Security tab (`app/api/auth/hub/password/return.ts`): opened, it
|
|
34
|
+
* names the spoke's registered origin and its `/account/security`, and a
|
|
35
|
+
* completed reset lands on that spoke's return route bound for the tab
|
|
36
|
+
* instead of this hub's sign-in (the reset ended the spoke's credential, so
|
|
37
|
+
* the spoke drops its session there and signs the person back in). A ref
|
|
38
|
+
* that does not open is ignored — never a redirect to a URL this hub did
|
|
39
|
+
* not seal.
|
|
31
40
|
*/
|
|
32
41
|
|
|
33
42
|
import { localeHref } from "@working-theory/ui";
|
|
@@ -37,13 +46,19 @@ import { getTranslations } from "next-intl/server";
|
|
|
37
46
|
import type { ReactElement } from "react";
|
|
38
47
|
|
|
39
48
|
import { resetSendConfigured } from "../../../../lib/auth-env";
|
|
49
|
+
import { resolveSecret } from "../../../../lib/auth-secret";
|
|
50
|
+
import { siteLogo } from "../../../../lib/site-logo";
|
|
51
|
+
import { openSecurityReturn } from "../../../api/auth/hub/password/return";
|
|
40
52
|
|
|
41
53
|
import { ResetPasswordCard } from "./reset-password-card";
|
|
42
|
-
import { siteLogo } from "../../../../lib/site-logo";
|
|
43
54
|
|
|
44
55
|
interface Props {
|
|
45
56
|
params: Promise<{ locale: string }>;
|
|
46
|
-
searchParams?: Promise<{
|
|
57
|
+
searchParams?: Promise<{
|
|
58
|
+
token?: string | string[];
|
|
59
|
+
error?: string | string[];
|
|
60
|
+
ref?: string | string[];
|
|
61
|
+
}>;
|
|
47
62
|
}
|
|
48
63
|
|
|
49
64
|
/** First value only — a repeated query param must not become an array here. */
|
|
@@ -69,6 +84,7 @@ export default async function ResetPasswordPage({
|
|
|
69
84
|
const query = searchParams ? await searchParams : {};
|
|
70
85
|
const token = firstValue(query.token);
|
|
71
86
|
const error = firstValue(query.error);
|
|
87
|
+
const ref = firstValue(query.ref);
|
|
72
88
|
|
|
73
89
|
const available = resetSendConfigured();
|
|
74
90
|
|
|
@@ -121,11 +137,15 @@ export default async function ResetPasswordPage({
|
|
|
121
137
|
backToSignIn: t("backToSignIn"),
|
|
122
138
|
};
|
|
123
139
|
|
|
140
|
+
// A spoke's Security tab, when the link was mailed for one (#11162).
|
|
141
|
+
const returnHref = ref ? openSecurityReturn(ref, resolveSecret()) : null;
|
|
142
|
+
|
|
124
143
|
return (
|
|
125
144
|
<ResetPasswordCard
|
|
126
145
|
logo={siteLogo()}
|
|
127
146
|
token={token}
|
|
128
147
|
signInHref={signInHref}
|
|
148
|
+
{...(returnHref !== null ? { completeHref: returnHref } : {})}
|
|
129
149
|
labels={labels}
|
|
130
150
|
errorLabels={{
|
|
131
151
|
resetFailed: t("resetFailed"),
|
|
@@ -33,8 +33,14 @@ export interface ResetPasswordCardProps {
|
|
|
33
33
|
logo?: ReactNode;
|
|
34
34
|
/** The `?token=` Better Auth redirected back with. May be empty. */
|
|
35
35
|
token: string;
|
|
36
|
-
/**
|
|
36
|
+
/** The sign-in page — the card's back link, and where a completed reset lands by default. */
|
|
37
37
|
signInHref: string;
|
|
38
|
+
/**
|
|
39
|
+
* Where a completed reset lands instead (#11162): a spoke's Security tab,
|
|
40
|
+
* for a link the hub mailed on that spoke's behalf. The page opens it from
|
|
41
|
+
* a sealed ref; this card never builds one.
|
|
42
|
+
*/
|
|
43
|
+
completeHref?: string;
|
|
38
44
|
/** Translated AuthCard labels (resolved server-side by the page). */
|
|
39
45
|
labels: AuthCardLabels;
|
|
40
46
|
/** Translated error copy. */
|
|
@@ -59,6 +65,7 @@ const defaultNavigate = (href: string): void => {
|
|
|
59
65
|
export function ResetPasswordCard({
|
|
60
66
|
token,
|
|
61
67
|
signInHref,
|
|
68
|
+
completeHref,
|
|
62
69
|
labels,
|
|
63
70
|
errorLabels,
|
|
64
71
|
navigate = defaultNavigate,
|
|
@@ -97,7 +104,7 @@ export function ResetPasswordCard({
|
|
|
97
104
|
return;
|
|
98
105
|
}
|
|
99
106
|
|
|
100
|
-
navigate(signInHref);
|
|
107
|
+
navigate(completeHref ?? signInHref);
|
|
101
108
|
};
|
|
102
109
|
|
|
103
110
|
const handleSubmit = (data: AuthSubmitData): void => {
|
|
@@ -78,6 +78,15 @@ jest.mock("../../../../../auth", () => ({
|
|
|
78
78
|
__esModule: true,
|
|
79
79
|
resolveSecret: () => TEST_SECRET,
|
|
80
80
|
}));
|
|
81
|
+
// #11095 D7 — the remembered-method cookie, read through `cookies()`.
|
|
82
|
+
const mockCookies: Record<string, string> = {};
|
|
83
|
+
jest.mock("next/headers", () => ({
|
|
84
|
+
__esModule: true,
|
|
85
|
+
cookies: async () => ({
|
|
86
|
+
get: (name: string) =>
|
|
87
|
+
name in mockCookies ? { name, value: mockCookies[name] } : undefined,
|
|
88
|
+
}),
|
|
89
|
+
}));
|
|
81
90
|
const mockClientInfo = jest.fn();
|
|
82
91
|
jest.mock("@working-theory/api-client", () => ({
|
|
83
92
|
__esModule: true,
|
|
@@ -123,6 +132,7 @@ async function renderPage(next?: string, error?: string): Promise<void> {
|
|
|
123
132
|
}
|
|
124
133
|
|
|
125
134
|
beforeEach(() => {
|
|
135
|
+
for (const name of Object.keys(mockCookies)) delete mockCookies[name];
|
|
126
136
|
mockGetActiveProviderIds.mockReset().mockReturnValue(["google"]);
|
|
127
137
|
mockIsResetAvailable.mockReset().mockReturnValue(false);
|
|
128
138
|
mockSocial.mockReset().mockResolvedValue({ data: {}, error: null });
|
|
@@ -365,7 +375,8 @@ describe("/sign-in page — the spoke back link (#8790 D2)", () => {
|
|
|
365
375
|
await renderPage(`/api/auth/hub/continue/${ref}`);
|
|
366
376
|
expect(mockClientInfo).toHaveBeenCalledWith("spoke_1");
|
|
367
377
|
const back = screen.getByTestId("auth-back-link");
|
|
368
|
-
|
|
378
|
+
// #11095 D5: the spoke's home — its /account would start the hub hop again.
|
|
379
|
+
expect(back).toHaveAttribute("href", "https://wendihenry.com/");
|
|
369
380
|
// This suite's next-intl shim returns messages uninterpolated, so the
|
|
370
381
|
// label's shape is what is asserted here; the ICU fill is next-intl's.
|
|
371
382
|
expect(back).toHaveTextContent(/^Back to/);
|
|
@@ -575,3 +586,43 @@ describe("/sign-in page — the Sign up toggle keeps the next (#9912 D4)", () =>
|
|
|
575
586
|
);
|
|
576
587
|
});
|
|
577
588
|
});
|
|
589
|
+
|
|
590
|
+
// #11095 AC-6 (D7): a returning person's card leads with the provider they
|
|
591
|
+
// last launched; a value that does not parse changes nothing.
|
|
592
|
+
describe("/sign-in page — the remembered method (#11095 D7)", () => {
|
|
593
|
+
it("with ailk-sign-in-method=google: Continue with Google first, no email field, and Use another way restores the card", async () => {
|
|
594
|
+
const user = userEvent.setup();
|
|
595
|
+
mockGetActiveProviderIds.mockReturnValue(["google", "magic-link"]);
|
|
596
|
+
mockCookies["ailk-sign-in-method"] = "google";
|
|
597
|
+
await renderPage();
|
|
598
|
+
const lead = screen.getByTestId("auth-sso-google");
|
|
599
|
+
expect(lead).toHaveTextContent(`${en.signIn.continueWith} ${en.signIn.google}`);
|
|
600
|
+
expect(screen.getAllByRole("button")[0]).toBe(lead);
|
|
601
|
+
expect(screen.queryByTestId("auth-email")).toBeNull();
|
|
602
|
+
const another = screen.getByTestId("sign-in-use-another-way");
|
|
603
|
+
expect(another).toHaveTextContent(en.signIn.useAnotherWay);
|
|
604
|
+
|
|
605
|
+
await user.click(another);
|
|
606
|
+
expect(screen.getByTestId("auth-email")).toBeInTheDocument();
|
|
607
|
+
expect(screen.getByTestId("auth-social-google")).toBeInTheDocument();
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
it.each([
|
|
611
|
+
["evil", ["google", "magic-link"]],
|
|
612
|
+
["github", ["google", "magic-link"]],
|
|
613
|
+
["", ["google", "magic-link"]],
|
|
614
|
+
])(
|
|
615
|
+
"a cookie of %j (not an active provider) renders exactly the no-cookie card",
|
|
616
|
+
async (value, active) => {
|
|
617
|
+
mockGetActiveProviderIds.mockReturnValue(active);
|
|
618
|
+
await renderPage();
|
|
619
|
+
const today = document.body.innerHTML;
|
|
620
|
+
document.body.innerHTML = "";
|
|
621
|
+
|
|
622
|
+
mockCookies["ailk-sign-in-method"] = value;
|
|
623
|
+
await renderPage();
|
|
624
|
+
expect(document.body.innerHTML).toBe(today);
|
|
625
|
+
expect(screen.queryByTestId("sign-in-use-another-way")).toBeNull();
|
|
626
|
+
},
|
|
627
|
+
);
|
|
628
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The remembered-method cookie (#11095 D7, AC-6): it names one provider id
|
|
3
|
+
* and nothing else, and only an id the page offers parses.
|
|
4
|
+
*/
|
|
5
|
+
import {
|
|
6
|
+
REMEMBERED_METHOD_COOKIE,
|
|
7
|
+
parseRememberedMethod,
|
|
8
|
+
rememberMethod,
|
|
9
|
+
} from "../remembered-method";
|
|
10
|
+
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
document.cookie = `${REMEMBERED_METHOD_COOKIE}=; Max-Age=0; Path=/`;
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe("parseRememberedMethod", () => {
|
|
16
|
+
it("answers an active google or github", () => {
|
|
17
|
+
expect(parseRememberedMethod("google", ["google", "github"])).toBe(
|
|
18
|
+
"google",
|
|
19
|
+
);
|
|
20
|
+
expect(parseRememberedMethod("github", ["github"])).toBe("github");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it.each([
|
|
24
|
+
[undefined, ["google"]],
|
|
25
|
+
["", ["google"]],
|
|
26
|
+
["evil", ["google"]],
|
|
27
|
+
["github", ["google"]],
|
|
28
|
+
["Google", ["google"]],
|
|
29
|
+
["google ", ["google"]],
|
|
30
|
+
] as const)("refuses %j with providers %j", (raw, providers) => {
|
|
31
|
+
expect(parseRememberedMethod(raw, [...providers])).toBeUndefined();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe("rememberMethod", () => {
|
|
36
|
+
it("writes the provider id alone, and null clears it", () => {
|
|
37
|
+
expect(REMEMBERED_METHOD_COOKIE).toBe("ailk-sign-in-method");
|
|
38
|
+
rememberMethod("google");
|
|
39
|
+
expect(document.cookie).toBe("ailk-sign-in-method=google");
|
|
40
|
+
rememberMethod(null);
|
|
41
|
+
expect(document.cookie).toBe("");
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -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: {
|
|
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
|
|
32
|
-
*
|
|
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}
|
|
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
|
+
}
|