firebase / firebase/firebase-android-sdk
Callback in client when token is revoked or user has been deleted
- Dominant language
- Java
- Stars
- 2.6k
- Forks
- 710
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 34
Description
## What feature would you like to see?
We would like to get some sort of reason or state of the user token every time we get a callback in IdTokenListener.
The best we have come up with, given what we have is a callback that returns IdAndToken object containing a nullable userId and token
```kotlin
/**
* Callback every time something changes with the user token
* returns IdAndToken that might contain a userId and a user token
* if we got a userId without a token it could mean that the token has
* been revoked and we could ask the user to re-authenticate
*/
private fun watchTokenChanges() = callbackFlow {
val listener = FirebaseAuth.IdTokenListener { firebaseAuthResult ->
if (firebaseAuthResult.currentUser?.getIdToken(false)?.isSuccessful == true) {
val token = firebaseAuthResult.currentUser?.getIdToken(false)?.result?.token
offerSafe(IdAndToken(firebaseAuthResult.currentUser?.uid, token))
} else {
offerSafe(IdAndToken(firebaseAuthResult.currentUser?.uid, null))
}
}
firebaseAuth.addIdTokenListener(listener)
awaitClose {
firebaseAuth.removeIdTokenListener(listener)
}
}.distinctUntilChanged()
```
A better api would be to have some sort of loggedInState on the currentUser
## How would you use it?
If the token has been revoked I would like to know that and let the user know that they need to re-authenticate.
Contributor guide
Assessment
This issue has not been assessed yet.