Listen to session changes.
sessionStatus
is a Flow<SessionStatus>
that emits the current session status. Everything related to the session is handled by this flow.events
is a Flow<AuthEvent>
that emits auth events. This flow is used to listen to auth events that are independent of the current session, like OTP errors, refresh failures, etc. Experimental.supabase.auth.sessionStatus.collect {
when(it) {
is SessionStatus.Authenticated -> {
println("Received new authenticated session.")
when(it.source) { //Check the source of the session
SessionSource.External -> TODO()
is SessionSource.Refresh -> TODO()
is SessionSource.SignIn -> TODO()
is SessionSource.SignUp -> TODO()
SessionSource.Storage -> TODO()
SessionSource.Unknown -> TODO()
is SessionSource.UserChanged -> TODO()
is SessionSource.UserIdentitiesChanged -> TODO()
}
}
SessionStatus.Initializing -> println("Initializing")
is SessionStatus.RefreshFailure -> {
println("Session expired and could not be refreshed")
}
is SessionStatus.NotAuthenticated -> {
if(it.isSignOut) {
println("User signed out")
} else {
println("User not signed in")
}
}
}
}
supabase.auth.events.collect {
when(it) {
is AuthEvent.OtpError ->
println("Found error in current URL / deeplink during the OAuth flow: ${it.error}")
is AuthEvent.RefreshFailure ->
println("Failed to refresh session: ${it.error}")
}
}