feat: Redirect authenticated users from auth pages and enable event-driven profile data refresh in the settings sidebar.
This commit is contained in:
@@ -1,8 +1,64 @@
|
||||
'use client';
|
||||
|
||||
import { useSession } from 'next-auth/react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
export default function AuthLayout({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
const { data: session, status } = useSession();
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
if (status === 'loading') return;
|
||||
|
||||
// Redirect authenticated users away from auth pages
|
||||
if (session) {
|
||||
const userRole = (session.user as any)?.role;
|
||||
if (userRole === 'AGENT') {
|
||||
router.replace('/agent/dashboard');
|
||||
} else {
|
||||
router.replace('/user/dashboard');
|
||||
}
|
||||
}
|
||||
}, [session, status, router]);
|
||||
|
||||
// Show loading spinner while checking authentication
|
||||
if (status === 'loading') {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-gradient-to-b from-[#c4d9d4] to-[#f0f5fc]">
|
||||
<div className="text-center">
|
||||
<img
|
||||
src="/assets/logo.svg"
|
||||
alt="RE-Quest"
|
||||
className="h-8 mx-auto mb-4"
|
||||
/>
|
||||
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-[#00293d] mx-auto"></div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Show loading while redirecting authenticated users
|
||||
if (session) {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-gradient-to-b from-[#c4d9d4] to-[#f0f5fc]">
|
||||
<div className="text-center">
|
||||
<img
|
||||
src="/assets/logo.svg"
|
||||
alt="RE-Quest"
|
||||
className="h-8 mx-auto mb-4"
|
||||
/>
|
||||
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-[#00293d] mx-auto"></div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Only render auth pages for unauthenticated users
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-gradient-to-b from-[#c4d9d4] to-[#f0f5fc] py-12 px-4">
|
||||
<div className="w-full max-w-[510px]">
|
||||
|
||||
Reference in New Issue
Block a user