A local-first personal finance app
Reload on all redirects to handle Cloudflare Access auth expiration (#4706)
Roger Goldfinger2f5464c735e1
diff --git a/packages/loot-core/src/platform/server/fetch/index.ts b/packages/loot-core/src/platform/server/fetch/index.tsindex f93196b0f5..f357473b69 100644--- a/packages/loot-core/src/platform/server/fetch/index.ts+++ b/packages/loot-core/src/platform/server/fetch/index.ts@@ -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;diff --git a/upcoming-release-notes/4706.md b/upcoming-release-notes/4706.mdnew file mode 100644index 0000000000..6e65b7b7c6--- /dev/null+++ b/upcoming-release-notes/4706.md@@ -0,0 +1,6 @@+---+category: Bugfix+authors: [rgoldfinger]+---++Reload on all redirects to handle Cloudflare Access expiration. This fixes issue #4422