import { redirect } from 'next/navigation'
import { getSessionUser } from '@/lib/auth'

/**
 * Signed-in users don't need the login form again.
 *
 * This used to be the proxy's job, but the proxy can only see that a cookie
 * is well signed, not that an admin revoked it (password reset, role change).
 * Doing it here, through getSessionUser, sends a live session to the
 * dashboard and lets a revoked one reach the form — instead of looping
 * between the two pages.
 */
export default async function LoginLayout({ children }: { children: React.ReactNode }) {
  const user = await getSessionUser()
  if (user) redirect('/dashboard')
  return children
}
