Initial commit

Next.js + Express event management app for Hope Family Church.
This commit is contained in:
2026-07-23 15:26:47 +02:00
commit fdd2d241b4
246 changed files with 57565 additions and 0 deletions
@@ -0,0 +1,27 @@
"use client";
import { useEffect } from "react";
import { useRouter } from "next/navigation";
import { useAuth } from "@/hooks/useAuth";
/**
* Use inside any client component that requires authentication.
* Returns `ready: true` only once auth has resolved and the user is confirmed.
* While loading or unauthenticated, `ready` is false — render null to prevent flash.
*
* @example
* const { ready, user, token } = useRequireAuth();
* if (!ready) return null;
*/
export function useRequireAuth(redirectTo = "/login") {
const { user, token, loading } = useAuth();
const router = useRouter();
useEffect(() => {
if (loading) return;
if (!user) router.replace(redirectTo);
}, [user, loading, router, redirectTo]);
const ready = !loading && !!user;
return { ready, user, token, loading };
}