chore: scaffold turbo monorepo with hono api and react admin web
This commit is contained in:
49
apps/web/src/routes/_authenticated/route.tsx
Normal file
49
apps/web/src/routes/_authenticated/route.tsx
Normal file
@@ -0,0 +1,49 @@
|
||||
import { createFileRoute, Navigate, Outlet } from '@tanstack/react-router'
|
||||
|
||||
import { AppHeader } from '@/components/layout/app-header'
|
||||
import { AppSidebar } from '@/components/layout/app-sidebar'
|
||||
import { SidebarInset, SidebarProvider } from '@/components/ui/sidebar'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import { useSession } from '@/lib/auth-client'
|
||||
|
||||
export const Route = createFileRoute('/_authenticated')({
|
||||
component: AuthenticatedLayout,
|
||||
})
|
||||
|
||||
/**
|
||||
* Layout for every authenticated page. The session lives in BetterAuth (Hono
|
||||
* API); while it resolves we render a loader, and without a session we bounce
|
||||
* the user to `/sign-in`.
|
||||
*/
|
||||
function AuthenticatedLayout() {
|
||||
const { data: session, isPending } = useSession()
|
||||
|
||||
if (isPending) {
|
||||
return <SessionLoading />
|
||||
}
|
||||
|
||||
if (!session) {
|
||||
return <Navigate to="/sign-in" replace />
|
||||
}
|
||||
|
||||
return (
|
||||
<SidebarProvider>
|
||||
<AppSidebar />
|
||||
<SidebarInset>
|
||||
<AppHeader />
|
||||
<div className="flex flex-1 flex-col gap-4 p-4 md:gap-6 md:p-6">
|
||||
<Outlet />
|
||||
</div>
|
||||
</SidebarInset>
|
||||
</SidebarProvider>
|
||||
)
|
||||
}
|
||||
|
||||
function SessionLoading() {
|
||||
return (
|
||||
<div className="space-y-4 p-6">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
<Skeleton className="h-64 w-full" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user