Reputation: 2314
How do I verify that FirebaseAuth.instance.currentUser()
still exists in Firebase Authentication (server-side)?
I deleted the user in my Firebase Console, but FirebaseAuth.instance.currentUser
still return a user.
So, how do I check that (await FirebaseAuth.instance.currentUser()).uid
is still in my Auth list in the Firebase Console?
Upvotes: 2
Views: 411
Reputation: 21
using angular,
isLoggedIn() {
return this.afAuth.authState.pipe(first())
}
doSomething() {
isLoggedIn().pipe(
tap(user => {
if (user) {
// do something
} else {
// do something else
}
})
)
.subscribe()
}
Upvotes: 0
Reputation: 126894
You can use the reload
method of FirebaseUser
.
final FirebaseUser firebaseUser = await FirebaseAuth.instance.currentUser();
await firebaseUser.reload();
// This should print `true` if the user is deleted in the Firebase Console.
print(await FirebaseAuth.instance.currentUser() == null);
If your user is deleted in the Firebase Console (or disabled) and you call reload
on the user in Flutter, the next time you call currentUser
, it should return null, i.e. there is no user authenticated on this device.
Upvotes: 4