Files
KomediruzeckiandGitHub 993a4145d2 feat(forms): sign-in and support say what is wrong at the field (slice 6 of 6) (#615)
The sign-in screen and dialog, the sign-in code steps, the two-factor challenge and its enroll and
disable steps, the new-password screen and the support form move onto the form kit from #602: a
refused entry is said under the field it is about, with the cursor there, and nothing is sent. A
wrong address or password stays one message for the whole form and marks neither field.

- shared/signInSchema.ts holds the address format, a new password's 8 characters and a support
  message's length. The routes answer a refused field with 400 { error, fields }, and a code that
  does not sign in with 401 at code.
- Every field has a label and takes its look from a class, so a marked field shows the kit's
  danger border. The sign-in fields keep the ids password managers use.
- The captcha goes through one gate: a send waits for its token, and each token is used for one
  request.
- The reset page says a link is invalid only when the Worker says so. A check that failed says
  so, with Try again.
- A mail call gives up after 10 seconds.
- Migration 0032 adds a column to login_codes. A sign-in code requested before the deploy stops
  working, and the person asks for a new one.

Slice 6 of 6 in docs/plans/2026-10-07-form-errors.md.
2026-10-10 11:38:29 +02:00

31 lines
1.3 KiB
TypeScript

/**
* Requests to the Worker that also wait for the work a route does after its answer: the mail, the
* code or the link it hands to ctx.waitUntil. SELF.fetch comes back with the answer alone, so a
* test that reads what that work wrote sends its request through here instead.
*/
import { createExecutionContext, env, waitOnExecutionContext } from 'cloudflare:test';
import worker, { type Env } from '../../src/index';
/** Send a request, and come back once its answer and everything it left running are done. */
export async function fetchSettled(input: string, init?: RequestInit): Promise<Response> {
const sent = fetchUnsettled(input, init);
const answer = await sent.answer;
await sent.settled();
return answer;
}
/**
* Send a request. `answer` is its answer, as SELF.fetch gives it; `settled` waits for the work it
* left running after the answer, for a test that holds that work (a held mail) and lets it go.
*/
export function fetchUnsettled(
input: string,
init?: RequestInit
): { answer: Promise<Response>; settled: () => Promise<void> } {
const ctx = createExecutionContext();
const answer = Promise.resolve(
worker.fetch(new Request(input, init), env as unknown as Env, ctx)
);
return { answer, settled: () => waitOnExecutionContext(ctx) };
}