auth-yes/scratch/hono_cookie_test.ts
Tyler Gillispie b9f4ccd71d feat(auth): resolve mobile cookie shadowing and synchronize tasks/path.md
- Implement iterative session cookie candidate resolution in getAuthenticatedUser
- Eliminate Hono first-match limitation causing mobile login redirect loops
- Use absolute UTC ISO strings for PostgreSQL session expiry queries
- Opportunistically clear host-level cookies upon shadow detection
- Ensure exhaustive server-side session revocation across all cookie candidates on logout
- Add automated regression test for cookie shadowing in server/main.test.ts
- Rename and standardize tasks/path.md with 5-template orchestrator standard
2026-08-24 21:48:33 -07:00

39 lines
867 B
TypeScript

import { Hono } from "jsr:@hono/hono@4";
import { getCookie } from "jsr:@hono/hono@4/cookie";
const app = new Hono();
app.get("/", (c) => {
const sessionId = getCookie(c, "session_id");
const allCookies = c.req.header("cookie");
return c.json({
parsedSessionId: sessionId,
rawCookieHeader: allCookies,
});
});
const req1 = new Request("http://localhost/", {
headers: {
"Cookie": "session_id=first-uuid; session_id=second-uuid",
},
});
const req2 = new Request("http://localhost/", {
headers: {
"cookie": "session_id=first-uuid; other=123",
},
});
async function run() {
console.log("Test 1: Multiple session_id cookies");
const res1 = await app.fetch(req1);
console.log(await res1.json());
console.log("Test 2: Lowercase cookie header");
const res2 = await app.fetch(req2);
console.log(await res2.json());
}
run();