Some checks are pending
E2E / Playwright e2e (push) Waiting to run
- Introduced turbopack alias for canvas in next.config.mjs. - Updated package.json scripts for development and branding tasks. - Added new dependencies for Tiptap extensions. - Implemented new demo layouts for agenda, contacts, drive, and mail applications. - Enhanced globals.css for improved theming and splash screen animations. - Added OAuth callback handling for drive mounts. - Updated layout components to integrate new demo shells and improve structure.
34 lines
1001 B
TypeScript
34 lines
1001 B
TypeScript
"use client"
|
|
|
|
import { useEffect, useState } from "react"
|
|
import { useAuthStore } from "@/lib/api/auth-store"
|
|
import { useIsDemoApp } from "@/lib/demo/use-is-demo-app"
|
|
|
|
/** Wait for auth persist hydrate before enabling API queries. */
|
|
export function useAuthReady() {
|
|
const isDemoApp = useIsDemoApp()
|
|
// Always false on first render so SSR and hydration markup match; zustand
|
|
// `hasHydrated()` can be true on the server (in-memory persist) before the
|
|
// client has read localStorage.
|
|
const [ready, setReady] = useState(false)
|
|
const authenticated = useAuthStore((s) => s.isAuthenticated())
|
|
|
|
useEffect(() => {
|
|
if (isDemoApp) {
|
|
setReady(true)
|
|
return
|
|
}
|
|
if (useAuthStore.persist.hasHydrated()) {
|
|
setReady(true)
|
|
return
|
|
}
|
|
const unsub = useAuthStore.persist.onFinishHydration(() => setReady(true))
|
|
return unsub
|
|
}, [isDemoApp])
|
|
|
|
return {
|
|
ready: isDemoApp ? true : ready,
|
|
authenticated: isDemoApp ? true : ready && authenticated,
|
|
}
|
|
}
|