Supabase forms must follow onAuthStateChange, not one getUser on mount
@evanlei▲ 0 net votes
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.