jajabarr
jajabarr

Reputation: 561

Can't remove currentUser.uid from device

Auth.auth().currentUser?.uid

This call returns a uid no matter if the user exists or not as an authenticated user. I have tried manually removing the user from the Authentication section of the Firebase web portal, and I have tried removing the user in Swift via:

Auth.auth().currentUser?.delete(completion: { (error) in

    print(error)
})

I then receive this error:

Optional(Error Domain=FIRAuthErrorDomain Code=17011 "There is no user record corresponding to this identifier. The user may have been deleted." UserInfo={NSLocalizedDescription=There is no user record corresponding to this identifier. The user may have been deleted., error_name=ERROR_USER_NOT_FOUND})

The uid persists even after deleting the app and rebuilding it on the device.

I just need to get the uid cleared when I remove a user, and for the life of me I can't make it happen. I really need to be able to test brand new devices/accounts using the app for the first time, which isn't possible with this persisting uid. What step am I missing here?

If it helps, I'm doing this with anonymous user accounts. Ideally I would be able to register a new anonymous account and see it appear each time I delete it from the device.

Upvotes: 0

Views: 302

Answers (2)

brandonscript
brandonscript

Reputation: 72885

If you're using anonymous user accounts, you're going to get an automatically generated UID that is tied to the current installed instance of your app. You can see in the docs:

let isAnonymous = user!.isAnonymous  // true
let uid = user!.uid

AFAIK, you can't log out/delete an anonymous user, because there is no authentication context to remove. Can you solve your issue by checking for both isAnonymous and uid at the same time, instead of trying to rely on the existence of uid?

Upvotes: 0

bojeil
bojeil

Reputation: 30808

This may be an Firebase Auth iOS bug. I have filed a bug with Firebase Auth. What you can do, is catch that error (when you try to delete the user) and on detection signOut the user so they are not persisted anymore.

Upvotes: 1

Related Questions