feat: rebuild fiscal clone architecture and harden coolify deployment
This commit is contained in:
22
frontend/hooks/use-auth-guard.ts
Normal file
22
frontend/hooks/use-auth-guard.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useSession } from '@/lib/better-auth';
|
||||
|
||||
export function useAuthGuard() {
|
||||
const { data: session, isPending } = useSession();
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
if (!isPending && !session) {
|
||||
router.replace('/auth/signin');
|
||||
}
|
||||
}, [isPending, session, router]);
|
||||
|
||||
return {
|
||||
session,
|
||||
isPending,
|
||||
isAuthenticated: Boolean(session?.user)
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user