Call auth.getUser() immediately after creating the server client in middleware
Per Supabase docs: do not run code between createServerClient and supabase.auth.getUser(). A simple mistake could cause random logouts.
Why This Matters
Running code between client creation and getUser() can corrupt the session cookie state, causing users to be randomly logged out with no clear cause.
Tags
nextjssupabaseAuthentication
Related Rules
Catch this automatically on every PR
BeforeMerge scans your pull requests against this rule and 3+ others. Get actionable feedback before code ships.