mirror of
https://github.com/Sosokker/go-chi-oapi-codegen-todolist.git
synced 2025-12-19 14:04:07 +01:00
42 lines
976 B
TypeScript
42 lines
976 B
TypeScript
"use client";
|
|
|
|
import { useEffect } from "react";
|
|
import { useRouter } from "next/navigation";
|
|
import { useAuthStore } from "@/store/auth-store";
|
|
import { Navbar } from "@/components/navbar";
|
|
|
|
export default function TodosLayout({
|
|
children,
|
|
}: {
|
|
children: React.ReactNode;
|
|
}) {
|
|
const { isAuthenticated, hydrated } = useAuthStore();
|
|
const router = useRouter();
|
|
|
|
useEffect(() => {
|
|
if (hydrated && !isAuthenticated) {
|
|
router.push("/login");
|
|
}
|
|
}, [hydrated, isAuthenticated, router]);
|
|
|
|
if (!hydrated) {
|
|
return (
|
|
<div className="flex items-center justify-center w-full h-full">
|
|
<div className="animate-spin rounded-full h-5 w-5 border-b-2 border-blue-500" />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (!isAuthenticated) {
|
|
router.push("/login");
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<div className="flex min-h-screen flex-col items-start mx-auto">
|
|
<Navbar />
|
|
<main className="flex-1 w-full py-2">{children}</main>
|
|
</div>
|
|
);
|
|
}
|