Skip to content

Commit b2e4ac5

Browse files
author
bourgeoa
committed
fix(header): prevent auth flicker and support session shape variants
1 parent 1c399bc commit b2e4ac5

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

src/mainPage/header.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,33 @@ export const HELP_MENU_LIST = [
3838
]
3939

4040
const HEADER_MOBILE_STYLE_ID = 'solid-ui-header-mobile-style'
41+
let authRefreshInFlight: Promise<void> | null = null
42+
43+
async function ensureAuthUserResolved (): Promise<void> {
44+
if (authn.currentUser()) return
45+
if (authRefreshInFlight) {
46+
await authRefreshInFlight
47+
return
48+
}
49+
50+
authRefreshInFlight = (async () => {
51+
try {
52+
await authn.checkUser()
53+
// Some auth stacks resolve session state asynchronously after first check.
54+
if (!authn.currentUser()) {
55+
await authn.checkUser()
56+
}
57+
} catch (_err) {
58+
// Keep header rendering resilient when auth refresh fails.
59+
}
60+
})()
61+
62+
try {
63+
await authRefreshInFlight
64+
} finally {
65+
authRefreshInFlight = null
66+
}
67+
}
4168

4269
type ManagedHeader = Header & {
4370
__solidPanesListenersAttached?: boolean
@@ -139,6 +166,7 @@ function attachHeaderListeners (header: ManagedHeader) {
139166

140167
export async function refreshHeader (outliner: OutlineManager, headerElement?: Header) {
141168
ensureMobileHeaderStyles()
169+
await ensureAuthUserResolved()
142170
const headerOptions = setHeaderOptions(outliner)
143171
const header = headerElement || document.querySelector('solid-ui-header') as Header | null
144172
if (!header) return null

src/mainPage/menu.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ const applyMenuCollapsedState = (navMenu: HTMLElement | null): void => {
5959
updateCollapseButtonPosition(navMenu, collapseBtn)
6060
}
6161

62-
const isLoggedIn = (): boolean => Boolean(authSession?.isActive)
62+
// Compatibility: solid-logic Session shape differs across stacks (info.isLoggedIn vs isActive/webId).
63+
const isLoggedIn = (): boolean => {
64+
const sessionAny = authSession as any
65+
return Boolean(sessionAny?.info?.isLoggedIn ?? sessionAny?.isActive ?? sessionAny?.webId)
66+
}
6367

6468
const setFooterVisibility = (loggedIn: boolean): void => {
6569
const footer = document.querySelector('solid-ui-footer') as HTMLElement | null

0 commit comments

Comments
 (0)