|
export function getAccessToken() { |
|
if (typeof window === 'undefined') { |
|
return null; |
|
} |
|
// Try URL first (admin sends token via URL on initial load) |
|
const urlToken = new URL(window.location.href).searchParams.get('access_token'); |
|
if (urlToken) { |
|
// Store for future SPA navigations |
|
sessionStorage.setItem('hydra_access_token', urlToken); |
|
return urlToken; |
|
} |
|
// Try sessionStorage (persists across SPA navigations) |
|
const sessionToken = sessionStorage.getItem('hydra_access_token'); |
|
if (sessionToken) { |
|
return sessionToken; |
|
} |
|
// Fallback to cookie |
|
return getTokenFromCookie(); |
|
} |
We should have a way to pass in a search params so that the access_token can be fetched from an SSR'd request where window isn't available, reducing the work integrators need to do to get access to private pages
volto-hydra/packages/hydra-js/hydra.js
Lines 7761 to 7779 in d787850
We should have a way to pass in a search params so that the access_token can be fetched from an SSR'd request where window isn't available, reducing the work integrators need to do to get access to private pages