fix auth store init with $effect
wrap authStore.initFromServer in $effect to react to data prop
This commit is contained in:
parent
f66b31fea8
commit
f29fd065b6
1 changed files with 5 additions and 8 deletions
|
|
@ -27,21 +27,18 @@
|
||||||
// Store scroll positions for each visited route
|
// Store scroll positions for each visited route
|
||||||
const scrollPositions = new Map<string, number>();
|
const scrollPositions = new Map<string, number>();
|
||||||
|
|
||||||
// Initialize auth store from server data immediately on load to ensure
|
// Initialize auth store from server data when data prop is populated
|
||||||
// Authorization headers are available for client-side API calls
|
// Use $effect to ensure we react to when server data is available
|
||||||
// Run immediately, not in effect to avoid timing issues
|
$effect(() => {
|
||||||
if (browser) {
|
if (browser && data?.auth) {
|
||||||
if (data?.auth) {
|
|
||||||
console.log('[+layout] Initializing authStore with token:', data.auth.accessToken ? 'present' : 'missing')
|
console.log('[+layout] Initializing authStore with token:', data.auth.accessToken ? 'present' : 'missing')
|
||||||
authStore.initFromServer(
|
authStore.initFromServer(
|
||||||
data.auth.accessToken,
|
data.auth.accessToken,
|
||||||
data.auth.user,
|
data.auth.user,
|
||||||
data.auth.expiresAt
|
data.auth.expiresAt
|
||||||
)
|
)
|
||||||
} else {
|
|
||||||
console.warn('[+layout] No auth data available to initialize authStore')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Save scroll position before navigating away and close sidebar
|
// Save scroll position before navigating away and close sidebar
|
||||||
beforeNavigate(({ from }) => {
|
beforeNavigate(({ from }) => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue