-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve user shelters loading and performance
- Loading branch information
1 parent
69893dd
commit 277d45f
Showing
2 changed files
with
12 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,16 @@ | ||
import { Loader2 } from "lucide-react"; | ||
import { redirect } from "next/navigation"; | ||
import { Suspense, type PropsWithChildren } from "react"; | ||
import { getServerAuthSession } from "~/server/auth"; | ||
"use client"; | ||
|
||
import { useSession } from "next-auth/react"; | ||
import { redirect, usePathname } from "next/navigation"; | ||
import { type PropsWithChildren } from "react"; | ||
|
||
export default function ShelterLayout({ children }: PropsWithChildren) { | ||
const pathname = usePathname(); | ||
const { data: session } = useSession(); | ||
|
||
export default async function ShelterLayout({ children }: PropsWithChildren) { | ||
const session = await getServerAuthSession(); | ||
if (!session) { | ||
redirect("/signin?callbackUrl=/user/shelters"); | ||
redirect(`/signin?callbackUrl=${pathname}`); | ||
} | ||
return ( | ||
<Suspense | ||
fallback={ | ||
<div className="flex w-full justify-center pt-28"> | ||
<Loader2 className="size-8 animate-spin" /> | ||
</div> | ||
} | ||
> | ||
{children} | ||
</Suspense> | ||
); | ||
|
||
return children; | ||
} |