feat: Centralize authentication redirects to middleware, remove client-side redirect logic, and refine logout process.

This commit is contained in:
pradeepkumar
2026-03-10 09:28:19 +05:30
parent 69eff70fbb
commit c7f1b89203
9 changed files with 77 additions and 70 deletions

View File

@@ -18,10 +18,11 @@ export default function AgentLayout({
useEffect(() => {
if (status === 'loading') return;
if (!session) {
router.replace('/login');
return;
}
// Don't redirect to /login here — the middleware handles that.
// Doing it here causes race conditions during logout (layout detects
// session loss and redirects to /login via client-side navigation,
// which can conflict with the server-side logout redirect).
if (!session) return;
// Redirect non-agents to user dashboard
const userRole = (session.user as any)?.role;