Some checks are pending
E2E / Playwright e2e (push) Waiting to run
- Added SessionGuard component to manage session expiration and online status. - Updated AuthProvider to streamline session fetching and handling. - Introduced IdentityProvidersSection for managing OAuth, SAML, and LDAP identity providers. - Implemented identity provider guides for easier configuration. - Enhanced mail settings with infinite scroll option for improved user experience. - Updated global styles and layout components for better consistency across the application.
22 lines
686 B
TypeScript
22 lines
686 B
TypeScript
import { useAuthStore } from "@/lib/api/auth-store"
|
|
import { fetchSession, applySessionToStore } from "@/lib/auth/session-sync"
|
|
|
|
let syncPromise: Promise<string | null> | null = null
|
|
|
|
/** Bearer token comes from httpOnly session cookies — never trust localStorage cache. */
|
|
export async function ensureAccessToken(): Promise<string | null> {
|
|
if (!syncPromise) {
|
|
syncPromise = (async () => {
|
|
const data = await fetchSession()
|
|
if (data && applySessionToStore(data)) {
|
|
return useAuthStore.getState().accessToken
|
|
}
|
|
useAuthStore.getState().logout()
|
|
return null
|
|
})().finally(() => {
|
|
syncPromise = null
|
|
})
|
|
}
|
|
return syncPromise
|
|
}
|