File tree Expand file tree Collapse file tree 4 files changed +24
-10
lines changed
platform/auth/serviceWorker Expand file tree Collapse file tree 4 files changed +24
-10
lines changed Original file line number Diff line number Diff line change @@ -67,15 +67,28 @@ self.addEventListener('fetch', (event) => {
6767 } )
6868 )
6969
70- // If redirected to external storage (GCS), follow without auth headers
71- // The signed URL contains its own authentication in query params
72- if (
73- response . type === 'opaqueredirect' ||
74- response . status === 302 ||
75- response . status === 301
76- ) {
70+ // Handle redirects to external storage (e.g., GCS signed URLs)
71+ if ( response . type === 'opaqueredirect' ) {
72+ // Opaqueredirect: redirect occurred but response is opaque (headers not accessible)
73+ // Re-fetch the original /api/view URL with redirect: 'follow'
74+ // Browser will:
75+ // 1. Send auth headers to /api/view (same-origin)
76+ // 2. Receive 302 redirect to GCS
77+ // 3. Automatically strip auth headers when following cross-origin redirect
78+ // 4. Use GCS signed URL authentication instead
79+ return fetch ( event . request . url , {
80+ method : 'GET' ,
81+ headers : headers ,
82+ redirect : 'follow'
83+ } )
84+ }
85+
86+ // Non-opaque redirect (status visible) - shouldn't normally happen with redirect: 'manual'
87+ // but handle as fallback
88+ if ( response . status === 302 || response . status === 301 ) {
7789 const location = response . headers . get ( 'location' )
7890 if ( location ) {
91+ // Follow redirect manually - do NOT include auth headers for external URLs
7992 return fetch ( location , {
8093 method : 'GET' ,
8194 redirect : 'follow'
Original file line number Diff line number Diff line change 8383 } )
8484
8585// Register auth service worker after Pinia is initialized (cloud-only)
86+ // Wait for registration to complete before mounting to ensure SW controls the page
8687if ( isCloud ) {
87- void import ( '@/platform/auth/serviceWorker' )
88+ await import ( '@/platform/auth/serviceWorker' )
8889}
8990
9091app . mount ( '#vue-app' )
Original file line number Diff line number Diff line change @@ -5,5 +5,5 @@ import { isCloud } from '@/platform/distribution/types'
55 * Tree-shaken for desktop/localhost builds via compile-time constant.
66 */
77if ( isCloud ) {
8- void import ( './register' )
8+ await import ( './register' )
99}
Original file line number Diff line number Diff line change @@ -54,4 +54,4 @@ function setupCacheInvalidation(): void {
5454 } )
5555}
5656
57- void registerAuthServiceWorker ( )
57+ await registerAuthServiceWorker ( )
You can’t perform that action at this time.
0 commit comments