fix: 修复未登录态授权刷新循环
Some checks failed
CI / verify (push) Has been cancelled

This commit is contained in:
2026-04-20 22:01:04 +08:00
parent 75944b1f1f
commit 39c7f0735f
5 changed files with 103 additions and 13 deletions

View File

@@ -157,6 +157,24 @@ describe('apiClient', () => {
);
});
it('does not refresh or emit auth changes for 401 responses without auth context', async () => {
fetchMock.mockResolvedValueOnce(createResponseMock({ status: 401 }));
const response = await fetchWithApiAuth('/api/runtime/protected', {
method: 'GET',
});
expect(response.status).toBe(401);
expect(fetchMock).toHaveBeenCalledTimes(1);
expect(fetchMock).toHaveBeenCalledWith(
'/api/runtime/protected',
expect.objectContaining({
credentials: 'same-origin',
}),
);
expect(window.dispatchEvent).not.toHaveBeenCalled();
});
it('retries transient get requests before unwrapping the response envelope', async () => {
fetchMock
.mockRejectedValueOnce(new TypeError('network unavailable'))