supermemory/apps/web/components/ensure-workspace.tsx
Prasanna721 c012f3b5c4 fix stale session cookie (#823)
- redirect to login when session is gone instead of blank screen
- show cached username while session restores so header doesn't flicker
- cleaned up redundant type casts and unused vars
2026-04-03 01:55:24 +00:00

27 lines
774 B
TypeScript

"use client"
import { useEffect } from "react"
import { usePathname, useRouter } from "next/navigation"
import { useAuth } from "@lib/auth-context"
export function EnsureWorkspace({ children }: { children: React.ReactNode }) {
const pathname = usePathname()
const router = useRouter()
const { session, organizations, isRestoring } = useAuth()
useEffect(() => {
if (isRestoring) return
if (!session) {
router.replace(
`/login?redirect=${encodeURIComponent(window.location.href)}`,
)
return
}
if (organizations === null) return
if (organizations.length > 0) return
if (pathname.startsWith("/onboarding")) return
router.replace("/onboarding/welcome?step=input")
}, [session, organizations, isRestoring, pathname, router])
return children
}