Fix redirect loop for users who need to set password

The auth layout was redirecting logged-in users to their dashboard even
when they still needed to set their password. This caused a redirect
loop: auth layout redirects to /jury, middleware redirects back to
/set-password, repeat until crash.

Now the auth layout checks mustSetPassword before redirecting, allowing
users to complete the password setup flow.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-04 00:41:32 +01:00
parent 0f956cf23f
commit a3cc73e49d

View File

@@ -16,7 +16,8 @@ export default async function AuthLayout({
} }
// Redirect logged-in users to their dashboard // Redirect logged-in users to their dashboard
if (session?.user) { // But NOT if they still need to set their password
if (session?.user && !session.user.mustSetPassword) {
const role = session.user.role const role = session.user.role
if (role === 'SUPER_ADMIN' || role === 'PROGRAM_ADMIN') { if (role === 'SUPER_ADMIN' || role === 'PROGRAM_ADMIN') {
redirect('/admin') redirect('/admin')