Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Offer a retry link on the stale sign-in link page (#18)

Regan Bellcddf9e9f7e24
diff --git a/plugins/auth/src/pages.ts b/plugins/auth/src/pages.ts
index 586684ba3..fc1feb480 100644
--- a/plugins/auth/src/pages.ts
+++ b/plugins/auth/src/pages.ts
@@ -166,7 +166,16 @@ export function confirmSignInPage(o: { brandName: string; action: string }): str
});
}
-export function problemPage(o: { brandName: string; heading: string; msg: string; detail?: string }): string {
+export function problemPage(o: {
+ brandName: string;
+ heading: string;
+ msg: string;
+ detail?: string;
+ retryUrl?: string;
+}): string {
+ const detail = o.detail ? `<p class="reason"><strong>Details</strong>${escapeHtml(o.detail)}</p>` : "";
+ const retry = o.retryUrl ? `<a class="btn" href="${escapeHtml(o.retryUrl)}">Request a new sign-in link</a>` : "";
+ const body = `${detail}${retry}`;
return page({
title: "Sign-in problem",
brandName: o.brandName,
@@ -174,7 +183,7 @@ export function problemPage(o: { brandName: string; heading: string; msg: string
warn: true,
heading: o.heading,
msg: o.msg,
- ...(o.detail ? { body: `<p class="reason"><strong>Details</strong>${escapeHtml(o.detail)}</p>` } : {}),
+ ...(body ? { body } : {}),
help: "If this keeps happening, contact your administrator.",
});
}
diff --git a/plugins/auth/src/server.ts b/plugins/auth/src/server.ts
index f4f9b5096..08c4d7c86 100644
--- a/plugins/auth/src/server.ts
+++ b/plugins/auth/src/server.ts
@@ -123,12 +123,24 @@ export function createAuthHandler(deps: AuthDeps): (req: IncomingMessage, res: S
const problem = (res: ServerResponse, status: number, heading: string, msg: string, detail?: string): void =>
sendHtml(res, status, problemPage({ brandName: cfg.brandName, heading, msg, ...(detail ? { detail } : {}) }));
+ const signInUrl = ((): string | undefined => {
+ try {
+ return new URL("/auth/login", cfg.redirectUri).toString();
+ } catch {
+ return undefined;
+ }
+ })();
+
const staleLink = (res: ServerResponse): void =>
- problem(
+ sendHtml(
res,
400,
- "This sign-in link no longer works",
- "Sign-in links work once and expire quickly. Request a fresh one and open it right away.",
+ problemPage({
+ brandName: cfg.brandName,
+ heading: "This sign-in link no longer works",
+ msg: "Sign-in links work once and expire quickly. Request a fresh one and open it right away.",
+ ...(signInUrl ? { retryUrl: signInUrl } : {}),
+ }),
);
async function authorizeForm(res: ServerResponse, params: URLSearchParams): Promise<void> {
diff --git a/plugins/auth/test/flow.test.ts b/plugins/auth/test/flow.test.ts
index b120946cb..ed0cf2eac 100644
--- a/plugins/auth/test/flow.test.ts
+++ b/plugins/auth/test/flow.test.ts
@@ -147,7 +147,9 @@ test("a replayed magic link is refused", async (t) => {
assert.equal((await openLink(h, link)).status, 302);
const replay = await openLink(h, link);
assert.equal(replay.status, 400);
- assert.match(await replay.text(), /no longer works/);
+ const stale = await replay.text();
+ assert.match(stale, /no longer works/);
+ assert.match(stale, /href="https:\/\/agent\.example\.test\/auth\/login"/);
});
test("a replayed authorization code is refused", async (t) => {
@@ -169,6 +171,7 @@ test("an expired magic link is refused", async (t) => {
h.now.ms += (h.cfg.linkTtlS + 60) * 1000;
const late = await openLink(h, link);
assert.equal(late.status, 400);
+ assert.match(await late.text(), /href="https:\/\/agent\.example\.test\/auth\/login"/);
assert.equal(
h.claims.calls.some((ids) => ids[0]?.startsWith("link:")),
false,