mirror of
https://github.com/actualbudget/actual.git
synced 2026-03-11 12:43:09 -05:00
Reload on all redirects to handle Cloudflare Access auth expiration (#4706)
* Reload on all redirects * Update index.ts * Create release notes * Update index.ts * Update index.ts * Update 4706.md --------- Co-authored-by: Roger Goldfinger <roger@remind101.com> Co-authored-by: Matt Fiddaman <github@m.fiddaman.uk>
This commit is contained in:
@@ -2,17 +2,18 @@ import * as connection from '../connection';
|
||||
|
||||
export const fetch = async (
|
||||
input: RequestInfo | URL,
|
||||
options?: RequestInit,
|
||||
options: RequestInit = {},
|
||||
): Promise<Response> => {
|
||||
// Set redirect to manual so that we can detect and respond to redirects.
|
||||
if (!options.redirect) options.redirect = 'manual';
|
||||
|
||||
const response = await globalThis.fetch(input, options);
|
||||
|
||||
// Detect if the API query has been redirected to a different origin. This may indicate that the
|
||||
// request has been intercepted by an authentication proxy
|
||||
const originalUrl = new URL(input instanceof Request ? input.url : input);
|
||||
const responseUrl = new URL(response.url);
|
||||
if (response.redirected && responseUrl.host !== originalUrl.host) {
|
||||
// Authentication proxies redirect when authentication has expired. In this case,
|
||||
// we want to fully reload and yeild control from the service worker back to the server.
|
||||
if (response.type === 'opaqueredirect') {
|
||||
connection.send('api-fetch-redirected');
|
||||
throw new Error(`API request redirected to ${responseUrl.host}`);
|
||||
throw new Error(`API request redirected`);
|
||||
}
|
||||
|
||||
return response;
|
||||
|
||||
6
upcoming-release-notes/4706.md
Normal file
6
upcoming-release-notes/4706.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
category: Bugfix
|
||||
authors: [rgoldfinger]
|
||||
---
|
||||
|
||||
Reload on all redirects to handle Cloudflare Access expiration. This fixes issue #4422
|
||||
Reference in New Issue
Block a user