Flutter: Listen to auth events

Receive a notification every time an auth event happens.

Examples

Listen to auth changes

final authSubscription = supabase.auth.onAuthStateChange.listen((data) \{
  final AuthChangeEvent event = data.event;
  final Session? session = data.session;
\});

Listen to a specific event

final authSubscription = supabase.auth.onAuthStateChange.listen((data) \{
  final AuthChangeEvent event = data.event;
  if (event == AuthChangeEvent.signedIn) \{
    // handle signIn
  \}
\});

Unsubscribe from auth subscription

final authSubscription = supabase.auth.onAuthStateChange((event, session) \{\});

authSubscription.cancel();