diff --git a/server/src/app.ts b/server/src/app.ts index ad525ab..b88fbb0 100644 --- a/server/src/app.ts +++ b/server/src/app.ts @@ -540,6 +540,9 @@ export function createApp(basePath = config.basePath): Hono { * `callback` is where the server sends it back. See oauth.ts. */ const OAUTH_STATE_COOKIE = `${config.cookieName}_signin`; + /** The look the browser asked the server's sign-in page for, if it is one we pass on. */ + const signInTheme = (value: string | undefined): "light" | "dark" | undefined => + value === "light" || value === "dark" ? value : undefined; api.get("/auth/oauth/start", async (c) => { if (!oauthEnabled()) return c.json({ error: "not_found" }, 404); @@ -561,6 +564,7 @@ export function createApp(basePath = config.basePath): Hono { base: upstreamFor(username), remember: c.req.query("remember") === "1", adding: front !== null, + theme: signInTheme(c.req.query("theme")), }); setCookie(c, OAUTH_STATE_COOKIE, state, { httpOnly: true, sameSite: "Lax", secure: isSecureRequest(c), path: `${basePath}/api/auth`, maxAge: 600 }); return c.redirect(location, 302); diff --git a/server/src/oauth.test.ts b/server/src/oauth.test.ts index e15528b..f3c4f48 100644 --- a/server/src/oauth.test.ts +++ b/server/src/oauth.test.ts @@ -119,6 +119,15 @@ test("start sends the browser to the server's page with PKCE and a bound state", assert.equal(jar.get("ihm_session_signin"), to.searchParams.get("state"), "the state is bound to this browser"); }); +test("start passes on the light or dark look for the server's page, and nothing else", async () => { + const look = async (theme: string) => + new URL((await call(`/api/auth/oauth/start?username=demo@example.com&theme=${encodeURIComponent(theme)}`)).headers.get("location")!).searchParams.get("theme"); + assert.equal(await look("dark"), "dark"); + assert.equal(await look("light"), "light"); + assert.equal(await look("