FIX: Bypass serviceworker cache for auth routes

This avoids samesite cookie-related issues in iOS PWAs during the authentication flow
This commit is contained in:
David Taylor 2020-03-31 15:47:13 +01:00 committed by Rafael dos Santos Silva
parent 5112648796
commit 0e3fa4072f

View File

@ -7,11 +7,15 @@ workbox.setConfig({
debug: false
});
var authUrl = "<%= Discourse.base_path %>/auth/";
var cacheVersion = "1";
// Cache all GET requests, so Discourse can be used while offline
workbox.routing.registerRoute(
new RegExp('.*?'), // Matches all, GET is implicit
function(args) {
return !(args.url.origin === location.origin && args.url.pathname.startsWith(authUrl));
}, // Match all except auth routes
new workbox.strategies.NetworkFirst({ // This will only use the cache when a network request fails
cacheName: "discourse-" + cacheVersion,
plugins: [