fix: browser context on password-change history, plain settings errors, New password label

Found in the browser check: change-password history rows had no browser
or IP, settings errors named internal fields, and the dialog's new
password field read just "Password".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-11-30 14:52:15 +08:00
1 parent 091503a820
commit dd9bbbe036
10 files changed
+69 -10

No files matched your search

@@ -0,0 +1,29 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
const mocks = vi.hoisted(() => ({ callMobileApi: vi.fn(), getToken: vi.fn() }));
vi.mock("@/app/lib/server/mobileApi", () => ({ callMobileApi: mocks.callMobileApi }));
vi.mock("@/app/lib/server/session", () => ({ getToken: mocks.getToken }));
import { POST } from "./route";
beforeEach(() => {
mocks.callMobileApi.mockReset();
mocks.getToken.mockReset();
});
describe("POST /api/auth/change-password: client context", () => {
it("forwards the browser IP and user agent for the login history", async () => {
mocks.getToken.mockResolvedValue("jwt-abc");
mocks.callMobileApi.mockResolvedValue({ ok: true, data: null });
const req = new Request("http://localhost/api/auth/change-password", {
method: "POST",
headers: { "x-forwarded-for": "198.51.100.7", "user-agent": "Browser/1.0" },
body: JSON.stringify({ currentPassword: "a", newPassword: "b", confirmPassword: "b" }),
}) as unknown as Parameters<typeof POST>[0];
await POST(req);
expect(mocks.callMobileApi.mock.calls[0][1].headers).toEqual({
"X-Client-Ip": "198.51.100.7",
"X-Client-User-Agent": "Browser/1.0",
});
});
});
@@ -35,6 +35,7 @@ describe("POST /api/auth/change-password", () => {
method: "POST",
body: { currentPassword: "Old#1", newPassword: "New#1", confirmPassword: "New#1" },
token: "jwt-abc",
headers: {},
});
});
@@ -2,6 +2,7 @@ import { NextResponse, type NextRequest } from "next/server";
import { callMobileApi } from "@/app/lib/server/mobileApi";
import { getToken } from "@/app/lib/server/session";
import { errorResponse, unauthorized } from "@/app/lib/server/apiRoute";
import { clientContextHeaders } from "@/app/lib/server/clientContext";
/** The signed-in admin changes their own password; only the three fields are forwarded, and nothing is logged. */
export async function POST(req: NextRequest) {
@@ -16,6 +17,8 @@ export async function POST(req: NextRequest) {
method: "POST",
body: { currentPassword, newPassword, confirmPassword },
token,
// The browser IP and user agent go into the login history rows this call writes.
headers: clientContextHeaders(req),
});
if (!result.ok) return errorResponse(result);
return new NextResponse(null, { status: 204 });