feat: Redirect authenticated users from auth pages and enable event-driven profile data refresh in the settings sidebar.

This commit is contained in:
pradeepkumar
2026-02-09 00:03:45 +05:30
parent a2384fc7d9
commit eefc4bcd78
3 changed files with 109 additions and 54 deletions

View File

@@ -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]">