Files
zeekay 6c65e3e941 @hanzo/app 0.2.0: the app SDK, renamed from @hanzo/rooms
Every import, the catalog pin and the docs name @hanzo/app and
github.com/hanzoai/app. lib/rooms.ts is lib/app.ts and
components/rooms.tsx is components/app.tsx.
2026-10-22 19:07:20 -07:00

59 lines
2.1 KiB
TypeScript

'use client'
import { useEffect } from 'react'
import { useRouter } from 'next/navigation'
import { View } from '@hanzo/ui'
import { useIam } from '@hanzo/iam/react'
import { useHydrated } from '@hanzo/app/lib/hydrated'
import { KEYS } from '@/components/settings/nav'
/**
* /dashboard — The entry door to the member dashboard.
*
* If the user is NOT authenticated:
* Immediately redirects to /login?next=/dashboard (or current search).
*
* If the user IS authenticated:
* Directs them to their Usage & Account Dashboard (/settings/organization/usage),
* or the requested tab (?tab=billing, ?tab=keys, ?tab=members, ?tab=home).
*/
export function DashboardDoor() {
const router = useRouter()
const hydrated = useHydrated()
const { isLoading, isAuthenticated } = useIam()
useEffect(() => {
if (!hydrated || isLoading) return
if (!isAuthenticated) {
// User is not logged in: make sure they go to /login
const search = window.location.search || ''
const here = `/dashboard${search}`
window.location.assign(`/login?next=${encodeURIComponent(here)}`)
return
}
// User is logged in: route to target tab or default usage dashboard
const p = new URLSearchParams(window.location.search)
const tab = p.get('tab')
if (tab === 'billing') {
router.replace('/settings/organization/billing')
} else if (tab === 'keys') {
window.location.assign(KEYS)
} else if (tab === 'members') {
router.replace('/settings/organization/members')
} else if (tab === 'home' || tab === 'workspace') {
router.replace('/home')
} else if (tab === 'general' || tab === 'settings') {
router.replace('/settings')
} else {
// Default: usage dashboard showing real-time API tokens, compute hours, models
router.replace('/settings/organization/usage')
}
}, [hydrated, isLoading, isAuthenticated, router])
// The rooms' veil (components/settings/Frame.tsx): the one element the export
// holds while the door decides where the reader goes.
return <View aria-hidden position="fixed" inset={0} bg="var(--background)" />
}