supermemory/apps/web/components/ensure-workspace.tsx
MaheshtheDev 1e1b0b1a37 feat(web): make /integrations a real route with connect deeplinks (#1155)
- Promote integrations from ?view=integrations to real /integrations and nested /integrations/[card] routes; the page body is shared via AppExperience and useViewMode is path-aware.
- Legacy ?view= URLs (and /settings/integrations) redirect to the new routes for back-compat; middleware/ensure-workspace allow the public routes.
- Add ?connect=<plugin|provider> deeplink that opens a card's connect modal instantly with a loading state (e.g. Hermes API key).
2026-06-23 20:42:29 +00:00

70 lines
1.7 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
const isOnboarding = pathname.startsWith("/onboarding")
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
}