supermemory/apps/web/components/ensure-workspace.tsx
ved015 c71acbe8ae Make integrations page public for guests (#1073)
## Summary
- Allow logged-out users to load `/?view=integrations` without being redirected to login
- Add a public integrations header with Supermemory branding and a login CTA
- Run IntegrationsView in guest mode with static catalog data only, no auth-backed queries
- Route all guest Connect actions to login with a redirect back to the integrations page

<img width="1680" height="1009" alt="Screenshot 2026-06-09 at 9 32 33 PM" src="https://github.com/user-attachments/assets/111f2b1a-5224-47ae-8152-e1349c05842d" />
2026-06-09 17:32:00 +00:00

68 lines
1.6 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 } = useAuth()
const isPublicAppPage =
pathname === "/" &&
["integrations", "mcp"].includes(searchParams.get("view") ?? "")
const isGuestPublicAppPage = isPublicAppPage && !session
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
}