Public: anyone can read this; the crew can change it.
/login and /sign-in send you to /signin, keeping where you were going #7702
scout/forge:scout/6038-login-and-sign-in-send-you-to-signin-kee → main 7 commits fork
6 files
changed +65
−2
src/http/server.ts +3
| @@ -120,6 +120,7 @@ import { | ||
| 120 | 120 | logoutSubmit, |
| 121 | 121 | newRepoPage, |
| 122 | 122 | newRepoSubmit, |
| 123 | signinAlias, | |
| 123 | 124 | signinPage, |
| 124 | 125 | signinSubmit, |
| 125 | 126 | signupPage, |
| @@ -744,6 +745,8 @@ export function buildRouter(): Router<Handler> { | ||
| 744 | 745 | router.add("GET", "/home/archived/:op", homeArchived); |
| 745 | 746 | router.add("POST", "/home/archived/:op/undo", homeArchiveUndo); |
| 746 | 747 | router.add("GET", "/signin", signinPage); |
| 748 | router.add("GET", "/login", signinAlias); | |
| 749 | router.add("GET", "/sign-in", signinAlias); | |
| 747 | 750 | router.add("POST", "/signin", signinSubmit); |
| 748 | 751 | router.add("GET", "/signin/parent", parentStart); |
| 749 | 752 | router.add("GET", "/signin/parent/callback", parentCallback); |
src/web/pages/site.ts +7
| @@ -440,6 +440,13 @@ export function signinPage(ctx: Ctx): Response { | ||
| 440 | 440 | ); |
| 441 | 441 | } |
| 442 | 442 | |
| 443 | /** `/login` and `/sign-in` are what people type: 308 to `/signin`, `next` kept only when `safeNext` allows it. */ | |
| 444 | export function signinAlias(ctx: Ctx): Response { | |
| 445 | const next = safeNext(ctx.url.searchParams.get("next")); | |
| 446 | const to = next === undefined ? "/signin" : `/signin?next=${encodeURIComponent(next)}`; | |
| 447 | return new Response(null, { status: 308, headers: { location: to } }); | |
| 448 | } | |
| 449 | ||
| 443 | 450 | /** The widget's public site key, when signup is gated on Turnstile. */ |
| 444 | 451 | function siteKey(ctx: Ctx): string | undefined { |
| 445 | 452 | const { turnstileSecret, turnstileSiteKey } = ctx.app.config; |
test/crew-team-scorecard.test.ts +2 −2
| @@ -31,7 +31,7 @@ describe("a scorecard row per team", () => { | ||
| 31 | 31 | function pull(author: string, title: string, merged: boolean, hours = 2, openedAt?: string) { |
| 32 | 32 | const issue = createIssue(app.db, { repoId, authorId: ids[author]!, title, kind: "pull" }); |
| 33 | 33 | if (!issue.ok) throw new Error(issue.error); |
| 34 | const opened = openedAt ?? "2026-10-01T00:00:00.000Z"; | |
| 34 | const opened = openedAt ?? new Date(Date.now() - 2 * 86_400_000).toISOString(); // inside the 30-day window whenever this runs | |
| 35 | 35 | app.db.query(`UPDATE issue SET created_at = ?2 WHERE id = ?1`).run(issue.value.id, opened); |
| 36 | 36 | const mergedAt = merged ? new Date(Date.parse(opened) + hours * 3_600_000).toISOString() : null; |
| 37 | 37 | app.db |
| @@ -114,7 +114,7 @@ describe("a scorecard row per team", () => { | ||
| 114 | 114 | expect(cards.has(three!)).toBe(false); |
| 115 | 115 | // The members' own cards are unchanged by pooling. |
| 116 | 116 | expect(crewScorecards(app.db).get(ids.a1!)!.reviewRounds).toBe(1); |
| 117 | // Oct 1 is inside the last 30 days; the idle team is still absent. | |
| 117 | // Two days ago is inside the last 30 days; the idle team is still absent. | |
| 118 | 118 | expect(teamScorecards(app.db, recentWindow()).has(three!)).toBe(false); |
| 119 | 119 | }); |
| 120 | 120 |
test/forge-looks.test.ts +2
| @@ -40,6 +40,8 @@ const NOT_A_PAGE: Record<string, string> = { | ||
| 40 | 40 | "/asks": "redirects to /#needs-you", |
| 41 | 41 | "/big": "redirects to /board?wall", |
| 42 | 42 | "/flow": "redirects to /boards", |
| 43 | "/login": "redirects to /signin", | |
| 44 | "/sign-in": "redirects to /signin", | |
| 43 | 45 | "/mcp": "a protocol endpoint, answers 405 to a GET", |
| 44 | 46 | "/_measure": "the page-load beacon, a POST endpoint", |
| 45 | 47 | "/events": "a live event stream that never ends", |
test/server-timing-sweep.test.ts +2
| @@ -44,8 +44,10 @@ const REDIRECTS = new Set([ | ||
| 44 | 44 | "/alice/forge/tells/new", |
| 45 | 45 | "/big", |
| 46 | 46 | "/flow", |
| 47 | "/login", | |
| 47 | 48 | "/settings/origins/callback", |
| 48 | 49 | "/settings/resilience", |
| 50 | "/sign-in", | |
| 49 | 51 | ]); |
| 50 | 52 | |
| 51 | 53 | /** Every GET pattern the router source registers, one-line or wrapped. */ |
test/signin-alias.test.ts added +49
| @@ -0,0 +1,49 @@ | ||
| 1 | /** `/login` and `/sign-in` send you to `/signin`, keeping a same-origin `next` (#6038). */ | |
| 2 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 3 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 4 | import { tmpdir } from "node:os"; | |
| 5 | import { join } from "node:path"; | |
| 6 | import { createApp, type App } from "../src/app.ts"; | |
| 7 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 8 | ||
| 9 | let dataDir = ""; | |
| 10 | let app: App; | |
| 11 | let servers: Servers; | |
| 12 | ||
| 13 | beforeAll(async () => { | |
| 14 | dataDir = await mkdtemp(join(tmpdir(), "forge-signin-alias-")); | |
| 15 | app = createApp({ dataDir, port: 0, url: "https://forge.example" }); | |
| 16 | servers = await serve(app); | |
| 17 | }); | |
| 18 | afterAll(async () => { | |
| 19 | await servers.stop(); | |
| 20 | app.close(); | |
| 21 | await rm(dataDir, { recursive: true, force: true }); | |
| 22 | }); | |
| 23 | ||
| 24 | const go = (path: string) => fetch(`${servers.url}${path}`, { redirect: "manual" }); | |
| 25 | ||
| 26 | for (const alias of ["/login", "/sign-in"]) { | |
| 27 | test(`${alias} answers 308 to /signin`, async () => { | |
| 28 | const res = await go(alias); | |
| 29 | expect(res.status).toBe(308); | |
| 30 | expect(res.headers.get("location")).toBe("/signin"); | |
| 31 | }); | |
| 32 | test(`${alias} keeps a same-origin next`, async () => { | |
| 33 | const res = await go(`${alias}?next=/settings`); | |
| 34 | expect(res.status).toBe(308); | |
| 35 | expect(res.headers.get("location")).toBe("/signin?next=%2Fsettings"); | |
| 36 | }); | |
| 37 | test(`${alias} drops an off-site next`, async () => { | |
| 38 | for (const bad of ["//evil.test", "https://evil.test"]) { | |
| 39 | const res = await go(`${alias}?next=${encodeURIComponent(bad)}`); | |
| 40 | expect(res.status).toBe(308); | |
| 41 | expect(res.headers.get("location")).toBe("/signin"); | |
| 42 | } | |
| 43 | }); | |
| 44 | } | |
| 45 | ||
| 46 | test("/signup is untouched", async () => { | |
| 47 | const res = await go("/signup"); | |
| 48 | expect(res.status).not.toBe(308); | |
| 49 | }); |
new above
offline