feat: guest auth (#141)

* feat: Start using guest auth

* feat: Implement more functionality to work as guest

* chore: update package and tweak public route

* chore: update root package json

* chore: update web package json

---------

Co-authored-by: Aslam H <iupin5212@gmail.com>
This commit is contained in:
Anselm Eickhoff
2024-09-06 21:11:43 +01:00
committed by GitHub
parent e61aae02d5
commit 844b1ae334
16 changed files with 138 additions and 205 deletions

View File

@@ -1,32 +1,30 @@
import { SignedInClient } from "@/components/custom/clerk/signed-in-client"
"use client"
import { Sidebar } from "@/components/custom/sidebar/sidebar"
import { JazzClerkAuth, JazzProvider } from "@/lib/providers/jazz-provider"
import { currentUser } from "@clerk/nextjs/server"
import { CommandPalette } from "@/components/custom/command-palette/command-palette"
import { useAccountOrGuest } from "@/lib/providers/jazz-provider"
import { usePathname } from "next/navigation"
import PublicHomeRoute from "@/components/routes/public/PublicHomeRoute"
export default async function PageLayout({ children }: { children: React.ReactNode }) {
const user = await currentUser()
export default function PageLayout({ children }: { children: React.ReactNode }) {
const { me } = useAccountOrGuest()
const pathname = usePathname()
if (!user) {
return children
if (me._type === "Anonymous" && pathname === "/") {
return <PublicHomeRoute />
}
return (
<JazzClerkAuth>
<SignedInClient>
<JazzProvider>
<div className="flex h-full min-h-full w-full flex-row items-stretch overflow-hidden">
<Sidebar />
<CommandPalette />
<div className="flex h-full min-h-full w-full flex-row items-stretch overflow-hidden">
<Sidebar />
<div className="flex min-w-0 flex-1 flex-col">
<main className="relative flex flex-auto flex-col place-items-stretch overflow-auto lg:my-2 lg:mr-2 lg:rounded-md lg:border">
{children}
</main>
</div>
</div>
</JazzProvider>
</SignedInClient>
</JazzClerkAuth>
{me._type !== "Anonymous" && <CommandPalette />}
<div className="flex min-w-0 flex-1 flex-col">
<main className="relative flex flex-auto flex-col place-items-stretch overflow-auto lg:my-2 lg:mr-2 lg:rounded-md lg:border">
{children}
</main>
</div>
</div>
)
}

View File

@@ -8,6 +8,7 @@ import { Toaster } from "@/components/ui/sonner"
import { ConfirmProvider } from "@/lib/providers/confirm-provider"
import { DeepLinkProvider } from "@/lib/providers/deep-link-provider"
import { GeistMono, GeistSans } from "./fonts"
import { JazzAndAuth } from "@/lib/providers/jazz-provider"
export const metadata: Metadata = {
title: "Learn Anything",
@@ -27,7 +28,7 @@ export default function RootLayout({
<ThemeProvider attribute="class" defaultTheme="system" enableSystem>
<JotaiProvider>
<ConfirmProvider>
{children}
<JazzAndAuth>{children}</JazzAndAuth>
<Toaster expand={false} />
</ConfirmProvider>
</JotaiProvider>