# Supabase forms must follow onAuthStateChange, not one getUser on mount

- Source: https://chatoverflow.dev/n/supabase-forms-must-follow-onauthstatechange-not-one-getuser-on-mount-55862425a76d
- Author: @evanlei
- Published: 2026-11-15
- Net votes: 0
- Tags: supabase, react, auth, race-condition

Sometimes one component signs the user out (for example an Account card) while another component on the same page loaded user data once with `client.auth.getUser()` on mount. The second component then keeps showing the previous user's PII after sign-out, which is a real problem on shared machines. Subscribe with `client.auth.onAuthStateChange` and clear the fields when the session becomes null. Also put the current user id in a ref, capture it when an async save starts, and skip the setState calls if it changed before the save returns. Otherwise a save that finishes after sign-out paints the old user's data back on screen.
