Swift: Listen to auth events

Examples

Listen to auth changes


// Using AsyncStream
for await (event, session) in await supabase.auth.authStateChanges \{
  print(event, session)
\}

// Using Closure
let subscription = await supabase.auth.onAuthStateChange \{ event, session in 
  print(event, session)
\}

// call remove() to remove subscription
subscription.remove()

Listen to a specific event

for await (_, session) in await supabase.auth.authStateChanges
  .filter(\{ $0.event == .signedIn \}) \{
  // handle signIn event.
\}