working auth

This commit is contained in:
2025-12-03 10:50:25 -05:00
parent 3e3e0b0466
commit 606b926886
389 changed files with 2793 additions and 12188 deletions
+34
View File
@@ -0,0 +1,34 @@
// components/ProtectedPage.tsx
"use client";
import { ReactNode, useEffect } from "react";
import { usePathname, useRouter } from "next/navigation";
import { useAuth } from "@/context/AuthContext";
export function ProtectedPage({ children }: { children: ReactNode }) {
const { user, loading } = useAuth();
const router = useRouter();
const pathname = usePathname();
useEffect(() => {
if (!loading && !user) {
const next = encodeURIComponent(pathname || "/");
router.replace(`/login?next=${next}`);
}
}, [loading, user, router, pathname]);
if (loading) {
return (
<main className="min-h-screen bg-black text-zinc-50 flex items-center justify-center">
<p className="text-sm text-zinc-500">Checking your session</p>
</main>
);
}
if (!user) {
// We just redirected; render nothing
return null;
}
return <>{children}</>;
}