From 21d60076ceb04ef7e8ce6d25a5e23a3a3575d4df Mon Sep 17 00:00:00 2001 From: hamster1963 <1410514192@qq.com> Date: Mon, 15 Jun 2026 18:51:19 +0800 Subject: [PATCH] fix(api): enhance token refresh handling with CSRF token support --- src/test/lib/nezha-api.test.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/test/lib/nezha-api.test.ts b/src/test/lib/nezha-api.test.ts index dc1a069..7b772a5 100644 --- a/src/test/lib/nezha-api.test.ts +++ b/src/test/lib/nezha-api.test.ts @@ -83,7 +83,7 @@ describe("nezha api fetchers", () => { it("refreshes the token when a logged-in browser session has cookies", async () => { Object.defineProperty(document, "cookie", { configurable: true, - value: "nezha_token=token", + value: "nezha_token=token; nz-csrf=test-csrf-token", }); const payload = { success: true, @@ -102,6 +102,11 @@ describe("nezha api fetchers", () => { await expect(fetchLoginUser()).resolves.toEqual(payload); expect(fetch).toHaveBeenNthCalledWith(1, "/api/v1/profile"); - expect(fetch).toHaveBeenNthCalledWith(2, "/api/v1/refresh-token"); + expect(fetch).toHaveBeenNthCalledWith(2, "/api/v1/refresh-token", { + method: "POST", + headers: { + "X-CSRF-Token": "test-csrf-token", + }, + }); }); });