mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-05-01 21:20:09 +00:00
- 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
27 lines
774 B
TypeScript
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
|
|
}
|