From 058e28fb8548ccd4189e5f4cc4263bab1659ef01 Mon Sep 17 00:00:00 2001 From: javi11 Date: Fri, 24 Apr 2026 15:41:13 +0200 Subject: [PATCH] fix(pwa): let auth proxies redirect before service worker serves cached HTML Replace navigateFallback with a NetworkFirst navigation route so that reverse-proxy authentication (e.g. Authelia) can issue 302 redirects to the login page before the service worker short-circuits navigation with a cached index.html. Only HTTP 200 responses are stored in the navigation cache, ensuring auth redirects are never cached and always reach the browser. --- frontend/vite.config.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 9c99f3d99..8ed594abf 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -65,6 +65,19 @@ export default defineConfig({ workbox: { globPatterns: ["**/*.{js,css,html,ico,png,svg,woff2}"], runtimeCaching: [ + // NetworkFirst for navigation so auth proxies (e.g. Authelia) can + // redirect unauthenticated requests before the SW serves cached HTML. + { + urlPattern: ({ request }) => request.mode === "navigate", + handler: "NetworkFirst", + options: { + cacheName: "navigation-cache", + networkTimeoutSeconds: 10, + cacheableResponse: { + statuses: [200], + }, + }, + }, { urlPattern: /^\/api\/.*/i, handler: "NetworkFirst", @@ -78,8 +91,6 @@ export default defineConfig({ }, }, ], - navigateFallback: "index.html", - navigateFallbackDenylist: [/^\/webdav/, /^\/sabnzbd/], }, }), ],