mirror of
https://github.com/Buriburizaem0n/nezha-dash-v1.git
synced 2026-09-19 09:40:14 +00:00
fix(api): enhance token refresh handling with CSRF token support
This commit is contained in:
@@ -83,7 +83,7 @@ describe("nezha api fetchers", () => {
|
|||||||
it("refreshes the token when a logged-in browser session has cookies", async () => {
|
it("refreshes the token when a logged-in browser session has cookies", async () => {
|
||||||
Object.defineProperty(document, "cookie", {
|
Object.defineProperty(document, "cookie", {
|
||||||
configurable: true,
|
configurable: true,
|
||||||
value: "nezha_token=token",
|
value: "nezha_token=token; nz-csrf=test-csrf-token",
|
||||||
});
|
});
|
||||||
const payload = {
|
const payload = {
|
||||||
success: true,
|
success: true,
|
||||||
@@ -102,6 +102,11 @@ describe("nezha api fetchers", () => {
|
|||||||
await expect(fetchLoginUser()).resolves.toEqual(payload);
|
await expect(fetchLoginUser()).resolves.toEqual(payload);
|
||||||
|
|
||||||
expect(fetch).toHaveBeenNthCalledWith(1, "/api/v1/profile");
|
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",
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user