onAuthStateChange method
Subscribe to auth state changes.
Fires whenever the user logs in, logs out, or initAuth completes. Returns an unsubscribe function — call it to stop listening.
final unsub = db.auth.onAuthStateChange((user, token) {
if (user != null) showHome();
else showLogin();
});
// cleanup
unsub();
Implementation
VoidCallback onAuthStateChange(
void Function(AppUser? user, String? token) callback,
) {
_authStateListeners.add(callback);
return () => _authStateListeners.remove(callback);
}