feat: improve PWA auth robustness and session management
This commit is contained in:
20
public/sw.js
20
public/sw.js
@@ -33,12 +33,15 @@ self.addEventListener('fetch', (event) => {
|
||||
const url = new URL(event.request.url);
|
||||
|
||||
// CRITICAL: Always bypass cache for auth, api, and supabase requests
|
||||
if (
|
||||
url.pathname.includes('/auth/') ||
|
||||
url.pathname.includes('/api/') ||
|
||||
url.hostname.includes('supabase.co')
|
||||
) {
|
||||
return; // Let it fall through to the network
|
||||
const isAuthRequest = url.pathname.includes('/auth/') ||
|
||||
url.pathname.includes('/v1/auth/') ||
|
||||
url.pathname.includes('/v1/token');
|
||||
const isApiRequest = url.pathname.includes('/api/');
|
||||
const isSupabaseRequest = url.hostname.includes('supabase.co');
|
||||
|
||||
if (isAuthRequest || isApiRequest || isSupabaseRequest) {
|
||||
// console.log('[SW] Bypassing cache for:', url.pathname);
|
||||
return;
|
||||
}
|
||||
|
||||
// Network first for all other requests, especially navigation
|
||||
@@ -58,7 +61,10 @@ self.addEventListener('fetch', (event) => {
|
||||
}
|
||||
return response;
|
||||
})
|
||||
.catch(() => {
|
||||
.catch((err) => {
|
||||
if (event.request.mode === 'navigate') {
|
||||
console.log('[SW] Navigation failed, attempting cache fallback for:', url.pathname);
|
||||
}
|
||||
return caches.match(event.request);
|
||||
})
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user