@jskit-ai/auth-web 0.2.18 → 0.2.20

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/CHANGELOG.md CHANGED
@@ -12,7 +12,7 @@
12
12
  - Sign-in has its one `h1`, "Sign in" (new message key `jskit.auth.login.title.login`; an app with other locales adds it with `npx jskit i18n export <locale>`), as every other mode and screen has; the reset and sign-out titles use the same `text-headline-medium` role.
13
13
  - The Register tab shows only when the provider lets anyone register (`features.password.selfRegister`), or for an invited person (an `invitationToken` in the address), so an app with `AUTH_LOCAL_SELF_REGISTRATION=false` offers no form that would be refused.
14
14
  - While the app has no account (`features.firstAccountSetupCode`), the registration form explains that the first account becomes the owner and asks for the setup code from the server's log or its hosting service, and sends it as `setupCode`. New message keys: `jskit.auth.login.firstAccount.explain` and `jskit.auth.login.field.setupCode`.
15
- - Email confirmation on the sign-in page: "Confirm your email" has a field for the emailed link or its code, and in development, when the registration's answer carries the link, shows it with a button that confirms it. Opening the emailed link (`/auth/login?confirmation_token=...`) confirms it and takes the code out of the address. Confirming signs the person in and opens the requested page. A sign-in refused with `auth.login.emailUnconfirmed` opens "Confirm your email" instead of an error. New route `POST /api/register/confirm`, which writes the new session's cookies, limited by `config.auth.rateLimits.registerConfirm` (10 a minute); the register answer carries `confirmationUrl` when the provider gives it. New message keys: `jskit.auth.register.confirmed`, `jskit.auth.login.field.confirmationCode`, `jskit.auth.login.confirmEmail.confirm`, `.devLink`, `.useDevLink` and `jskit.auth.login.error.confirmRegistrationFailed`.
15
+ - Email confirmation on the sign-in page: "Confirm your email" has a field for the emailed link or its code, and in development, when the registration's answer carries the link, shows it with a button that confirms it. Confirming sends the registration's password with the code, from the field "Password you registered with", which keeps the password just typed to register or sign in. Opening the emailed link (`/auth/login?confirmation_token=...`) takes the code out of the address and asks for that password ("Enter your password to finish confirming your email.") before it confirms, so a link opened alone creates nothing; a wrong password shows the provider's refusal and keeps the form. Confirming signs the person in and opens the requested page. A sign-in refused with `auth.login.emailUnconfirmed` opens "Confirm your email" instead of an error. New route `POST /api/register/confirm`, which writes the new session's cookies, limited by `config.auth.rateLimits.registerConfirm` (10 a minute); the register answer carries `confirmationUrl` when the provider gives it. New message keys: `jskit.auth.register.confirmed`, `jskit.auth.login.field.confirmationCode`, `jskit.auth.login.confirmEmail.confirm`, `.devLink`, `.useDevLink`, `.passwordHint`, `.linkOpened`, `jskit.auth.login.field.registrationPassword`, `jskit.auth.login.subtitle.confirmEmailPassword` and `jskit.auth.login.error.confirmRegistrationFailed`.
16
16
  - The auth routes' rate limits apply, per client address: `login`, `register`, `loginOtpRequest` and `loginOtpVerify` 10 a minute; `registerConfirmationResend` and `passwordForgot` 5; `oauthStart`, `oauthComplete`, `passwordRecovery` and `passwordReset` 20; `devLoginAs` 30. A refused request answers 429 with `kernel.http.rateLimited` and `Retry-After`, and the login page shows it.
17
17
  - `config.auth.rateLimits.<route>` changes a route's limit (`{ max, timeWindow }`, merged over the default) or removes it (`false`); an unknown route name or a malformed value stops startup. `AuthWebFeature` therefore requires `runtime.config`, which every installed runtime provides.
18
18
  - The sign-in and sign-out screens use Material 3 colour roles and type: an elevated card on `surface-container` (the whole screen on phones), the selected sign-in mode on `secondary-container`, and the remembered-account and email-confirmation notes on `secondary-container`, without the tinted gradient and borders. The profile menu's button is Material 3's 40dp text button inside material-web's 48dp touch target instead of a fixed 48px height.
package/locales/en.json CHANGED
@@ -18,7 +18,8 @@
18
18
  "forgot": "We will send password reset instructions to your email.",
19
19
  "otp": "Request a one-time login code and verify it below.",
20
20
  "confirmEmailSentTo": "Open the confirmation link sent to {email} to finish signing in.",
21
- "confirmEmailInbox": "Open the confirmation link from your inbox to finish signing in."
21
+ "confirmEmailInbox": "Open the confirmation link from your inbox to finish signing in.",
22
+ "confirmEmailPassword": "Enter your password to finish confirming your email."
22
23
  },
23
24
  "submit": {
24
25
  "login": "Sign in",
@@ -38,6 +39,7 @@
38
39
  "confirmPassword": "Confirm password",
39
40
  "otpCode": "One-time code",
40
41
  "confirmationCode": "Confirmation link or code",
42
+ "registrationPassword": "Password you registered with",
41
43
  "setupCode": "Setup code"
42
44
  },
43
45
  "confirmEmail": {
@@ -47,7 +49,9 @@
47
49
  "resent": "If an account exists for that email, a confirmation email has been sent.",
48
50
  "confirm": "Confirm",
49
51
  "devLink": "Development: no email is sent, so here is the confirmation link.",
50
- "useDevLink": "Confirm with this link"
52
+ "useDevLink": "Confirm with this link",
53
+ "passwordHint": "Confirming your email needs the password you chose when you registered.",
54
+ "linkOpened": "Enter the password you chose when you registered. If you did not register, or no longer know that password, register again."
51
55
  },
52
56
  "firstAccount": {
53
57
  "explain": "This app has no account yet. Its first account becomes its owner, so it needs the setup code the server wrote in its log when it started, or that its hosting service shows its owner."
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/auth-web",
3
- "version": "0.2.18",
3
+ "version": "0.2.20",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "jskit test"
@@ -25,10 +25,10 @@
25
25
  "./locales/en.json": "./locales/en.json"
26
26
  },
27
27
  "peerDependencies": {
28
- "@jskit-ai/auth-core": "0.2.13",
29
- "@jskit-ai/http-runtime": "0.2.13",
30
- "@jskit-ai/kernel": "0.2.13",
31
- "@jskit-ai/shell-web": "0.2.16",
28
+ "@jskit-ai/auth-core": "0.2.15",
29
+ "@jskit-ai/http-runtime": "0.2.15",
30
+ "@jskit-ai/kernel": "0.2.15",
31
+ "@jskit-ai/shell-web": "0.2.18",
32
32
  "@tanstack/vue-query": "^5.90.5",
33
33
  "pinia": "^4.0.3",
34
34
  "vue": "^3.5.44",
@@ -120,6 +120,21 @@ the standard app-owned managed-preview identity executable,
120
120
  surface and placement declarations into the application's ordinary config and
121
121
  placement files.
122
122
 
123
+ The pages live under `src/pages/auth/`, so the app defines an `auth` surface
124
+ open to everyone in `config/public.js`, under the foundations' `public` access
125
+ policy (`surfaceAccessPolicies.public = {}`):
126
+
127
+ ```js
128
+ config.surfaceDefinitions.auth = {
129
+ id: "auth",
130
+ label: "Sign in",
131
+ pagesRoot: "auth",
132
+ requiresAuth: false,
133
+ requiresWorkspace: false,
134
+ accessPolicyId: "public"
135
+ };
136
+ ```
137
+
123
138
  ## Variation points
124
139
 
125
140
  Change provider, routes, labels, page wrappers, permitted login methods, profile
@@ -189,7 +189,8 @@ export function useLoginViewActions({ state, validation, queryClient, errorRunti
189
189
  state.enterEmailConfirmationPendingState({
190
190
  emailAddress: normalizedEmail,
191
191
  message: registerCompletion.message,
192
- confirmationUrl: registerResult?.confirmationUrl
192
+ confirmationUrl: registerResult?.confirmationUrl,
193
+ password: registerPayload.password
193
194
  });
194
195
  return;
195
196
  }
@@ -257,7 +258,11 @@ export function useLoginViewActions({ state, validation, queryClient, errorRunti
257
258
  if (error?.code !== "auth.login.emailUnconfirmed") {
258
259
  throw error;
259
260
  }
260
- state.enterEmailConfirmationPendingState({ emailAddress: normalizedEmail, message: serverMessage(error) });
261
+ state.enterEmailConfirmationPendingState({
262
+ emailAddress: normalizedEmail,
263
+ message: serverMessage(error),
264
+ password: loginPayload.password
265
+ });
261
266
  return;
262
267
  }
263
268
  state.applyRememberedAccountPreference({
@@ -422,12 +427,17 @@ export function useLoginViewActions({ state, validation, queryClient, errorRunti
422
427
  }
423
428
 
424
429
  /**
425
- * Confirms a registration from its link's code, or from the whole link,
426
- * which signs the person in, and opens the requested page.
430
+ * Confirms a registration from its link's code, or from the whole link, with
431
+ * the password it was registered with, which signs the person in, and opens
432
+ * the requested page.
427
433
  * @param {unknown} codeOrLink
428
434
  */
429
435
  async function confirmRegistration(codeOrLink) {
430
- const confirmPayload = { token: confirmationTokenFromInput(codeOrLink) };
436
+ const confirmPayload = {
437
+ token: confirmationTokenFromInput(codeOrLink),
438
+ password: String(state.password.value || "")
439
+ };
440
+ state.passwordTouched.value = true;
431
441
  state.registrationConfirmPending.value = true;
432
442
  clearTransientMessages();
433
443
  try {
@@ -458,8 +468,9 @@ export function useLoginViewActions({ state, validation, queryClient, errorRunti
458
468
  }
459
469
  }
460
470
 
471
+ // The link this page was opened with, otherwise the code or link the person entered.
461
472
  function confirmRegistrationCode() {
462
- return confirmRegistration(state.confirmationCode.value);
473
+ return confirmRegistration(state.confirmationLinkToken.value || state.confirmationCode.value);
463
474
  }
464
475
 
465
476
  function confirmRegistrationFromLink() {
@@ -530,13 +541,16 @@ export function useLoginViewActions({ state, validation, queryClient, errorRunti
530
541
 
531
542
  async function initializeOnMounted() {
532
543
  state.applyRememberedAccountHint(readRememberedAccountHint());
533
- // Opened from a registration's confirmation email.
544
+ // Opened from a registration's confirmation email: confirming it asks for the registration's password.
534
545
  const confirmationToken = takeConfirmationTokenFromLocation();
535
546
  state.loading.value = true;
536
547
  try {
537
548
  const session = await refreshSession();
538
549
  if (confirmationToken) {
539
- await confirmRegistration(confirmationToken);
550
+ state.enterEmailConfirmationPendingState({
551
+ message: t("jskit.auth.login.confirmEmail.linkOpened"),
552
+ linkToken: confirmationToken
553
+ });
540
554
  return;
541
555
  }
542
556
  const callbackHandled = await handleOAuthCallbackIfPresent();
@@ -72,6 +72,8 @@ export function useLoginViewState({ placementContext }) {
72
72
  const confirmationUrl = ref("");
73
73
  // A confirmation code or link the person types or pastes.
74
74
  const confirmationCode = ref("");
75
+ // The code of the confirmation link this page was opened with, confirmed with the password typed next to it.
76
+ const confirmationLinkToken = ref("");
75
77
  const invitationToken = ref(readWindowSearchParam("invitationToken") || readWindowSearchParam("inviteToken"));
76
78
 
77
79
  const isLogin = computed(() => mode.value === LOGIN_MODE);
@@ -109,6 +111,9 @@ export function useLoginViewState({ placementContext }) {
109
111
  const authTitle = computed(() => modeText(AUTH_TITLE_BY_MODE));
110
112
  const authSubtitle = computed(() => {
111
113
  if (isEmailConfirmationPending.value) {
114
+ if (confirmationLinkToken.value) {
115
+ return t("jskit.auth.login.subtitle.confirmEmailPassword");
116
+ }
112
117
  const maskedEmail = maskEmail(pendingEmailConfirmationAddress.value);
113
118
  if (maskedEmail) {
114
119
  return t("jskit.auth.login.subtitle.confirmEmailSentTo", { email: maskedEmail });
@@ -254,6 +259,7 @@ export function useLoginViewState({ placementContext }) {
254
259
  pendingEmailConfirmationMessage.value = "";
255
260
  confirmationUrl.value = "";
256
261
  confirmationCode.value = "";
262
+ confirmationLinkToken.value = "";
257
263
  }
258
264
  clearTransientMessages();
259
265
  resetTransientValidationState();
@@ -268,11 +274,24 @@ export function useLoginViewState({ placementContext }) {
268
274
  }
269
275
  }
270
276
 
271
- function enterEmailConfirmationPendingState({ emailAddress = "", message = "", confirmationUrl: url = "" } = {}) {
277
+ /**
278
+ * Shows "Confirm your email". Confirming takes the registration's password:
279
+ * the one just typed to register or sign in stays in its field, and a page
280
+ * opened from a confirmation link (`linkToken`) asks for it.
281
+ */
282
+ function enterEmailConfirmationPendingState({
283
+ emailAddress = "",
284
+ message = "",
285
+ confirmationUrl: url = "",
286
+ password: typedPassword = "",
287
+ linkToken = ""
288
+ } = {}) {
272
289
  switchMode(EMAIL_CONFIRMATION_MODE);
273
290
  pendingEmailConfirmationAddress.value = normalizeEmailAddress(emailAddress);
274
291
  pendingEmailConfirmationMessage.value = String(message || "").trim();
275
292
  confirmationUrl.value = String(url || "").trim();
293
+ password.value = String(typedPassword || "");
294
+ confirmationLinkToken.value = String(linkToken || "").trim();
276
295
  }
277
296
 
278
297
  function goToMainScreen() {
@@ -309,6 +328,7 @@ export function useLoginViewState({ placementContext }) {
309
328
  pendingEmailConfirmationAddress,
310
329
  confirmationUrl,
311
330
  confirmationCode,
331
+ confirmationLinkToken,
312
332
  invitationToken,
313
333
  isLogin,
314
334
  isRegister,
@@ -45,6 +45,7 @@ function useLoginView() {
45
45
  setupCode: state.setupCode,
46
46
  confirmationUrl: state.confirmationUrl,
47
47
  confirmationCode: state.confirmationCode,
48
+ confirmationLinkToken: state.confirmationLinkToken,
48
49
  registrationConfirmPending: state.registrationConfirmPending,
49
50
  confirmRegistrationCode: actions.confirmRegistrationCode,
50
51
  confirmRegistrationFromLink: actions.confirmRegistrationFromLink,
@@ -61,6 +61,39 @@
61
61
  </p>
62
62
  </div>
63
63
 
64
+ <!-- Confirming takes the password the registration was made with, so only its owner can confirm it. -->
65
+ <v-text-field
66
+ v-model="password"
67
+ data-testid="auth-confirmation-password"
68
+ :label="t('jskit.auth.login.field.registrationPassword')"
69
+ :hint="t('jskit.auth.login.confirmEmail.passwordHint')"
70
+ persistent-hint
71
+ :type="showPassword ? 'text' : 'password'"
72
+ variant="outlined"
73
+ density="comfortable"
74
+ autocomplete="current-password"
75
+ :error-messages="passwordErrorMessages"
76
+ :append-inner-icon="showPassword ? '$visibilityOff' : '$visibility'"
77
+ @click:append-inner="togglePasswordVisibility"
78
+ @blur="passwordTouched = true"
79
+ class="mb-5"
80
+ />
81
+
82
+ <div v-if="confirmationLinkToken" class="email-confirmation-link mb-5">
83
+ <v-btn
84
+ class="text-none"
85
+ variant="flat"
86
+ color="primary"
87
+ size="large"
88
+ type="submit"
89
+ data-testid="auth-confirmation-link-submit"
90
+ :disabled="!password"
91
+ :loading="registrationConfirmPending"
92
+ >
93
+ {{ t("jskit.auth.login.confirmEmail.confirm") }}
94
+ </v-btn>
95
+ </div>
96
+
64
97
  <div v-if="confirmationUrl" class="email-confirmation-dev-link mb-5" data-testid="auth-confirmation-dev-link">
65
98
  <p class="text-body-medium on-surface-variant mb-2">{{ t("jskit.auth.login.confirmEmail.devLink") }}</p>
66
99
  <p class="email-confirmation-url text-body-small mb-3">{{ confirmationUrl }}</p>
@@ -69,6 +102,7 @@
69
102
  variant="flat"
70
103
  color="primary"
71
104
  data-testid="auth-confirmation-dev-confirm"
105
+ :disabled="!password"
72
106
  :loading="registrationConfirmPending"
73
107
  @click="confirmRegistrationFromLink"
74
108
  >
@@ -76,7 +110,10 @@
76
110
  </v-btn>
77
111
  </div>
78
112
 
79
- <div v-if="canEnterConfirmationCode" class="email-confirmation-code d-flex align-start ga-2 mb-5">
113
+ <div
114
+ v-if="canEnterConfirmationCode && !confirmationLinkToken"
115
+ class="email-confirmation-code d-flex align-start ga-2 mb-5"
116
+ >
80
117
  <v-text-field
81
118
  v-model="confirmationCode"
82
119
  data-testid="auth-confirmation-code"
@@ -93,7 +130,7 @@
93
130
  size="large"
94
131
  type="submit"
95
132
  data-testid="auth-confirmation-submit"
96
- :disabled="!confirmationCode.trim()"
133
+ :disabled="!confirmationCode.trim() || !password"
97
134
  :loading="registrationConfirmPending"
98
135
  >
99
136
  {{ t("jskit.auth.login.confirmEmail.confirm") }}
@@ -319,6 +356,7 @@ const {
319
356
  setupCode,
320
357
  confirmationUrl,
321
358
  confirmationCode,
359
+ confirmationLinkToken,
322
360
  registrationConfirmPending,
323
361
  confirmRegistrationFromLink,
324
362
  emailConfirmationMessage,
@@ -387,3 +387,77 @@ for (const refusal of [
387
387
  assert.equal(reports[0]?.message, refusal.payload.error);
388
388
  });
389
389
  }
390
+
391
+ test("a page opened from a confirmation link asks for the registration's password, and confirming sends both", async (t) => {
392
+ const state = createMinimalLoginViewState("/home");
393
+ Object.assign(state, { confirmationLinkToken: { value: "" }, passwordTouched: { value: false } });
394
+ state.password.value = "";
395
+ const pending = [];
396
+ state.enterEmailConfirmationPendingState = (entry) => {
397
+ pending.push(entry);
398
+ state.confirmationLinkToken.value = entry.linkToken;
399
+ };
400
+ const destinations = [];
401
+ const addresses = [];
402
+ const originalWindow = globalThis.window;
403
+ globalThis.window = {
404
+ location: {
405
+ href: "https://example.com/auth/login?confirmation_token=link-code&returnTo=%2Fhome",
406
+ replace: (path) => destinations.push(path)
407
+ },
408
+ history: { replaceState: (_state, _title, url) => addresses.push(url) }
409
+ };
410
+ t.after(() => {
411
+ if (originalWindow === undefined) delete globalThis.window;
412
+ else globalThis.window = originalWindow;
413
+ clearAuthCsrfTokenCache();
414
+ });
415
+ const confirmations = [];
416
+ let signedIn = false;
417
+ t.mock.method(globalThis, "fetch", async (url, options = {}) => {
418
+ const method = String(options.method || "GET").toUpperCase();
419
+ if (url === "/api/session" && method === "GET") {
420
+ return createJsonResponse({ authenticated: signedIn, csrfToken: "csrf-session" });
421
+ }
422
+ assert.equal(`${method} ${url}`, "POST /api/register/confirm");
423
+ const body = JSON.parse(options.body);
424
+ confirmations.push(body);
425
+ if (body.password !== "the registration's password") {
426
+ return createJsonResponse({
427
+ error: "That is not the password this registration was made with. Enter the password you registered with, or register again.",
428
+ code: "auth.local.register.confirmationPasswordInvalid"
429
+ }, { status: 400 });
430
+ }
431
+ signedIn = true;
432
+ return createJsonResponse({ ok: true, email: "ada@example.com", username: "Ada", message: "Your email is confirmed." });
433
+ });
434
+ const actions = useLoginViewActions({
435
+ state,
436
+ validation: {},
437
+ queryClient: { fetchQuery: ({ queryFn }) => queryFn() },
438
+ errorRuntime: { report() {} }
439
+ });
440
+
441
+ // Opening the link takes its code out of the address and asks for the password; nothing is confirmed yet.
442
+ await actions.initializeOnMounted();
443
+ assert.deepEqual(addresses, ["/auth/login?returnTo=%2Fhome"]);
444
+ assert.equal(pending.length, 1);
445
+ assert.equal(pending[0].linkToken, "link-code");
446
+ assert.deepEqual(confirmations, []);
447
+
448
+ // Without a password nothing is sent; a wrong one is refused and the page stays.
449
+ await actions.confirmRegistrationCode();
450
+ assert.deepEqual(confirmations, []);
451
+ assert.notEqual(state.errorMessage.value, "");
452
+ state.password.value = "a wrong password";
453
+ await actions.confirmRegistrationCode();
454
+ assert.deepEqual(confirmations, [{ token: "link-code", password: "a wrong password" }]);
455
+ assert.match(state.errorMessage.value, /^That is not the password this registration was made with\./u);
456
+ assert.deepEqual(destinations, []);
457
+
458
+ // The registration's password confirms, signs in and opens the requested page.
459
+ state.password.value = "the registration's password";
460
+ await actions.confirmRegistrationCode();
461
+ assert.deepEqual(confirmations.at(-1), { token: "link-code", password: "the registration's password" });
462
+ assert.deepEqual(destinations, ["/home"]);
463
+ });
@@ -174,7 +174,7 @@ test("registration confirmation: the register answer carries the development lin
174
174
  };
175
175
  },
176
176
  async confirmRegistration(input) {
177
- events.push({ type: "confirm", token: input.token });
177
+ events.push({ type: "confirm", token: input.token, password: input.password });
178
178
  return {
179
179
  actor: { displayName: "Ada", email: "ada@example.com" },
180
180
  session: { access_token: "confirm-a", refresh_token: "confirm-r" }
@@ -202,7 +202,7 @@ test("registration confirmation: the register answer carries the development lin
202
202
  const confirmRoute = route("/api/register/confirm");
203
203
  assert.deepEqual(confirmRoute.config.rateLimit, { max: 10, timeWindow: 60_000 });
204
204
  const confirmReply = createReplyStub();
205
- await confirmRoute.handler({ body: { token: "dev-token" } }, confirmReply);
205
+ await confirmRoute.handler({ body: { token: "dev-token", password: "correct horse battery staple" } }, confirmReply);
206
206
  assert.equal(confirmReply.statusCode, 200);
207
207
  assert.deepEqual(confirmReply.payload, {
208
208
  ok: true,
@@ -216,7 +216,7 @@ test("registration confirmation: the register answer carries the development lin
216
216
  assert.deepEqual(
217
217
  events.filter((entry) => entry.type === "confirm" || (entry.type === "writeSession" && entry.session)),
218
218
  [
219
- { type: "confirm", token: "dev-token" },
219
+ { type: "confirm", token: "dev-token", password: "correct horse battery staple" },
220
220
  { type: "writeSession", session: { access_token: "confirm-a", refresh_token: "confirm-r" } }
221
221
  ]
222
222
  );
@@ -269,7 +269,7 @@ test("register waits for email confirmation, and the other modes reach their req
269
269
  await finish(api);
270
270
  });
271
271
 
272
- test("email confirmation: the development link, a pasted link after an unconfirmed sign-in, and the emailed link", options, async () => {
272
+ test("email confirmation takes the registration's password: the development link, a pasted link after an unconfirmed sign-in, and the emailed link", options, async () => {
273
273
  const session = {
274
274
  ...SIGNED_OUT,
275
275
  authCapabilities: { ...CAPABILITIES, features: { ...CAPABILITIES.features, emailConfirmationCode: true } }
@@ -291,6 +291,15 @@ test("email confirmation: the development link, a pasted link after an unconfirm
291
291
  },
292
292
  "POST /api/register/confirm": (body) => {
293
293
  confirmations.push(body.token);
294
+ if (body.password !== "Correct-horse-1") {
295
+ return {
296
+ status: 400,
297
+ json: {
298
+ error: "That is not the password this registration was made with. Enter the password you registered with, or register again.",
299
+ code: "auth.local.register.confirmationPasswordInvalid"
300
+ }
301
+ };
302
+ }
294
303
  if (body.token === "expired-token") {
295
304
  return {
296
305
  status: 400,
@@ -314,7 +323,7 @@ test("email confirmation: the development link, a pasted link after an unconfirm
314
323
  return api;
315
324
  }
316
325
 
317
- // Registering in development shows the link, and its button confirms and signs in.
326
+ // Registering in development shows the link, and its button confirms with the password just typed and signs in.
318
327
  const registering = await openConfirmingApp();
319
328
  await registering.page.goto("/auth/login?mode=register&returnTo=/home");
320
329
  await registering.page.getByLabel("Email").fill("ada@example.com");
@@ -327,7 +336,7 @@ test("email confirmation: the development link, a pasted link after an unconfirm
327
336
  assert.deepEqual(confirmations, ["dev-token-1"]);
328
337
  await finish(registering);
329
338
 
330
- // Signing in before confirming opens "Confirm your email", where a pasted link confirms.
339
+ // Signing in before confirming opens "Confirm your email", where a pasted link confirms with the password typed.
331
340
  const signingIn = await openConfirmingApp();
332
341
  await signingIn.page.goto("/auth/login?returnTo=/home");
333
342
  await signIn(signingIn.page, "ada@example.com", "Correct-horse-1");
@@ -341,17 +350,29 @@ test("email confirmation: the development link, a pasted link after an unconfirm
341
350
  assert.deepEqual(confirmations.at(-1), "pasted-token-2");
342
351
  await finish(signingIn);
343
352
 
344
- // An emailed link confirms on opening; one that expired says so, and its code leaves the address.
353
+ // An emailed link asks for the registration's password, and its code leaves the address. A wrong password, or a link
354
+ // that expired, says so; the right password confirms and signs in.
345
355
  const expired = await openConfirmingApp();
346
356
  await expired.page.goto("/auth/login?confirmation_token=expired-token&returnTo=/home");
357
+ await expect(expired.page.getByText("Enter your password to finish confirming your email.")).toBeVisible();
358
+ assert.equal(new URL(expired.page.url()).search, "?returnTo=%2Fhome");
359
+ await expect(expired.page.getByTestId("auth-confirmation-link-submit")).toBeDisabled();
360
+ await expired.page.getByLabel("Password you registered with", { exact: true }).fill("Correct-horse-1");
361
+ await expired.page.getByTestId("auth-confirmation-link-submit").click();
347
362
  await expect.poll(async () => (await reports(expired.page)).at(-1)?.message)
348
363
  .toBe("This confirmation link is invalid or has expired. Register again to get a new one.");
349
- assert.equal(new URL(expired.page.url()).search, "?returnTo=%2Fhome");
350
364
  await finish(expired);
351
365
  const emailed = await openConfirmingApp();
352
366
  await emailed.page.goto("/auth/login?confirmation_token=emailed-token-3&returnTo=/home");
367
+ await emailed.page.getByLabel("Password you registered with", { exact: true }).fill("a wrong password");
368
+ await emailed.page.getByTestId("auth-confirmation-link-submit").click();
369
+ await expect.poll(async () => (await reports(emailed.page)).at(-1)?.message).toBe(
370
+ "That is not the password this registration was made with. Enter the password you registered with, or register again."
371
+ );
372
+ await emailed.page.getByLabel("Password you registered with", { exact: true }).fill("Correct-horse-1");
373
+ await emailed.page.getByLabel("Password you registered with", { exact: true }).press("Enter");
353
374
  await waitForHome(emailed.page);
354
- assert.deepEqual(confirmations.slice(-2), ["expired-token", "emailed-token-3"]);
375
+ assert.deepEqual(confirmations.slice(-3), ["expired-token", "emailed-token-3", "emailed-token-3"]);
355
376
  await finish(emailed);
356
377
  });
357
378