Job Description
Now I have a clear picture. Let me analyze the issue.
Issue #2 root cause analysis:
The OnboardingForm uses useActionState(completeOnboarding, initialState) which is the React 19 / Next.js 15 progressive enhancement pattern. The submit button has no onClick handler that would unmount anything (unlike the sign-out bug), so this is NOT the same React unmounting problem.
The real issue is a redirect loop. Here's what happens:
User fills form, clicks "Get Started"
Server action completeOnboarding runs successfully — DB updates, unstable_update() refreshes JWT, then calls redirect() to /worker/dashboard (or /employer/dashboard)
The redirect() from a server action causes a navigation
Edge middleware intercepts the redirect target at authorized() callback
The authorized() callback reads the JWT — but the crucial question is: does the middleware see the updated JWT with the new role, or the old JWT without a role?
If unstable_update() doesn't correctly update the cookie that the middleware reads on the same redirect response, the middleware still sees role = null and redirects back to /onboarding (line 121 in auth.config.ts).
However, this was supposedly verified working on 2026-03-04. Let me check if there's another possibility — the useActionState signature might be wrong for React 19 / Next.js 15.
Explore: Check useActionState signature — Read