mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 15:42:24 +00:00
fix(auth): bring a deep link back to its page after signing in
A home-screen shortcut, a notification tap or a bookmark opened without a session landed on the sign-in page with a bare URL, and after signing in the person was on the dashboard instead of the page they asked for. The sign-in page already honoured a sanitised `next`; neither redirect set one. The proxy now passes the request's own path and query as `next` (the bare start page goes without one). The shell does the same when the account answer ends a session on a protected page, except after a deliberate sign-out: the marker a confirmed session leaves is gone by then, so the next person on the device starts from a bare sign-in page rather than the page the previous one left.
This commit is contained in:
1 parent
75b879279f
commit
6c5a6eacbb
7 files changed
+152
-37
No files matched your search
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$comment": "Comment lines that open with a release version, per file under src/. Maintained by src/__tests__/version-stamp-ratchet.test.ts.",
|
||||
"count": 2892,
|
||||
"total": 9220,
|
||||
"total": 9217,
|
||||
"entries": {
|
||||
"__tests__/account-payload-consumer-guard.test.ts": 2,
|
||||
"__tests__/acting-account-boundary-guard.test.ts": 7,
|
||||
@@ -2892,7 +2892,7 @@
|
||||
"lib/withings/sync.ts": 6,
|
||||
"lib/withings/webhook-handler.ts": 3,
|
||||
"lib/workouts/list-read.ts": 1,
|
||||
"proxy.ts": 27,
|
||||
"proxy.ts": 26,
|
||||
"types/analytics.ts": 8,
|
||||
"types/backups.ts": 1
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ describe("proxy early exits carry the baseline security headers", () => {
|
||||
|
||||
it("unauthenticated page redirect to /auth/login", () => {
|
||||
const res = proxy(makeRequest("/dashboard"));
|
||||
expect(res.headers.get("location")).toMatch(/\/auth\/login$/);
|
||||
expect(res.headers.get("location")).toMatch(/\/auth\/login(\?|$)/);
|
||||
expectBaselineHeaders(res);
|
||||
});
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ describe("proxy.ts onboarding redirect (v1.4.22 C4)", () => {
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.headers.get("location")).toBeNull();
|
||||
const anonymous = proxy(makeRequest("/insights"));
|
||||
expect(anonymous.headers.get("location")).toMatch(/\/auth\/login$/);
|
||||
expect(anonymous.headers.get("location")).toMatch(/\/auth\/login(\?|$)/);
|
||||
});
|
||||
|
||||
it("passes through when hl_onboarding cookie is absent (completed users)", () => {
|
||||
@@ -123,7 +123,7 @@ describe("proxy.ts onboarding redirect (v1.4.22 C4)", () => {
|
||||
// were still in place it would short-circuit through public-path
|
||||
// handling and 200 instead.
|
||||
expect([307, 308]).toContain(res.status);
|
||||
expect(res.headers.get("location")).toMatch(/\/auth\/login$/);
|
||||
expect(res.headers.get("location")).toMatch(/\/auth\/login(\?|$)/);
|
||||
});
|
||||
|
||||
it("still treats subroutes /onboarding/<x> as the onboarding surface", () => {
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* The edge sends a visitor without a session to the sign-in page with the
|
||||
* page they asked for in `next`, so a home-screen shortcut or a notification
|
||||
* tap still arrives there after signing in. The sign-in page re-checks the
|
||||
* value (`sanitizeSameOriginPath`); the proxy only ever puts in the
|
||||
* request's own path and query.
|
||||
*/
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
vi.mock("@/lib/process-type", () => ({
|
||||
shouldRunWeb: () => true,
|
||||
}));
|
||||
|
||||
import { proxy } from "../proxy";
|
||||
|
||||
function signInRedirect(pathAndQuery: string): URL {
|
||||
const res = proxy(new NextRequest(`http://localhost${pathAndQuery}`));
|
||||
expect([307, 308]).toContain(res.status);
|
||||
return new URL(res.headers.get("location")!, "http://localhost");
|
||||
}
|
||||
|
||||
describe("proxy.ts sign-in redirect", () => {
|
||||
it.each([
|
||||
"/measurements?add=WEIGHT&source=shortcut",
|
||||
"/mood?add=1",
|
||||
"/medications",
|
||||
"/?source=pwa",
|
||||
])("carries %s to the sign-in page", (target) => {
|
||||
const location = signInRedirect(target);
|
||||
expect(location.pathname).toBe("/auth/login");
|
||||
expect(location.searchParams.get("next")).toBe(target);
|
||||
});
|
||||
|
||||
it("sends the bare start page to a bare sign-in page", () => {
|
||||
const location = signInRedirect("/");
|
||||
expect(location.pathname).toBe("/auth/login");
|
||||
expect(location.search).toBe("");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user