mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-08-23 07:24:29 +00:00
New /brain route creates the org straight from signup and redirects into the Slack install, so onboarding has no domain-confirmation step. Returning from OAuth shows an Open Slack handoff instead of a toast. Also models the terminal research error state: polling stops, the UI retries once, and the docked header no longer gates Continue on research finishing.
74 lines
1.9 KiB
TypeScript
74 lines
1.9 KiB
TypeScript
"use client"
|
|
|
|
import { useEffect } from "react"
|
|
import { usePathname, useRouter, useSearchParams } from "next/navigation"
|
|
import { useAuth } from "@lib/auth-context"
|
|
import { Loader2 } from "lucide-react"
|
|
|
|
function WorkspaceLoadingShell() {
|
|
return (
|
|
<div className="flex min-h-dvh items-center justify-center bg-[#05080D]">
|
|
<Loader2
|
|
className="size-6 animate-spin text-white/40"
|
|
aria-label="Loading workspace"
|
|
/>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export function EnsureWorkspace({ children }: { children: React.ReactNode }) {
|
|
const pathname = usePathname()
|
|
const router = useRouter()
|
|
const searchParams = useSearchParams()
|
|
const { session, organizations, isRestoring, isSessionPending } = useAuth()
|
|
|
|
const isPublicAppPage =
|
|
pathname === "/integrations" ||
|
|
pathname === "/integrations/mcp" ||
|
|
(pathname === "/" &&
|
|
["integrations", "mcp"].includes(searchParams.get("view") ?? ""))
|
|
const isGuestPublicAppPage = isPublicAppPage && !session && !isSessionPending
|
|
// /brain is the Slack-first Company Brain entry: it creates the org itself.
|
|
const isOnboarding =
|
|
pathname.startsWith("/onboarding") ||
|
|
pathname === "/brain" ||
|
|
pathname.startsWith("/brain/")
|
|
|
|
useEffect(() => {
|
|
if (isGuestPublicAppPage) return
|
|
if (isRestoring) return
|
|
if (!session) {
|
|
router.replace(
|
|
`/login?redirect=${encodeURIComponent(window.location.href)}`,
|
|
)
|
|
return
|
|
}
|
|
if (organizations === null) return
|
|
if (organizations.length > 0) return
|
|
if (isOnboarding) return
|
|
router.replace("/onboarding")
|
|
}, [
|
|
session,
|
|
organizations,
|
|
isRestoring,
|
|
isOnboarding,
|
|
router,
|
|
isGuestPublicAppPage,
|
|
])
|
|
|
|
const showLoading =
|
|
!isGuestPublicAppPage &&
|
|
(isRestoring ||
|
|
(!session && !isRestoring) ||
|
|
(session && organizations === null) ||
|
|
(session &&
|
|
organizations !== null &&
|
|
organizations.length === 0 &&
|
|
!isOnboarding))
|
|
|
|
if (showLoading) {
|
|
return <WorkspaceLoadingShell />
|
|
}
|
|
|
|
return children
|
|
}
|