I used to be questioning what can be a stable move to forestall a number of Firebase nameless customers from being created on a single machine.
We at the moment use the next API to create an nameless person:
Auth.auth().signInAnonymously
And the next code to signal out:
Auth.auth().signOut
To hyperlink an nameless person with an Apple account, we use:
person.hyperlink(with: oAuthCredential)
Under is our present move, which leads to a number of nameless customers being created for a single machine.
-
On the sign-in web page, the person faucets "Proceed as visitor" -> the primary nameless person is created.
-
On the primary app web page, the person faucets "Proceed with Apple" -> the nameless person is linked to the Apple account.
-
The person faucets “Signal out”.
-
On the sign-in web page, the person faucets "Proceed as visitor" once more -> a second nameless person is created.
-
On the primary app web page, the person faucets "Proceed with Apple". For the reason that Apple account is already linked to the primary person, Firebase indicators the person again in as the primary person.
-
Consequently, the second nameless person turns into a “zombie” person.
If steps 3-5 are repeated, extra "zombie" nameless customers will proceed to be created, as proven within the screenshot.

My query is: what’s a stable and beneficial move to forestall this case?
func updateBasedOnLoginStatus() {
if let person = Auth.auth().currentUser, person.isAnonymous {
// Present Apple join button, disguise signal out button.
appleSignUpButton.isHidden = false
signOutButton.isHidden = true
} else {
// Cover Apple join button, present signal out button.
appleView.isHidden = true
signOutButton.isHidden = false
}
}
// https://stackoverflow.com/questions/79615957/firebase-auth-link-anonymous-user-to-apple
non-public func handleOAuthCredentialAsync(_ oAuthCredential: OAuthCredential) {
Activity {
defer {
updateBasedOnLoginStatus()
}
if let person = Auth.auth().currentUser, person.isAnonymous {
do {
_ = strive await person.hyperlink(with: oAuthCredential)
} catch let linkError as NSError {
if linkError.code == AuthErrorCode.credentialAlreadyInUse.rawValue {
if let newCredential = linkError.userInfo[AuthErrorUserInfoUpdatedCredentialKey] as? OAuthCredential {
do {
_ = strive await Auth.auth().signIn(with: newCredential)
} catch {
Utils.showErrorAlert(viewController: self, message: error.localizedDescription)
}
}
}
}
} else {
// We should not attain right here. This web page is dealing with nameless person to login person.
do {
_ = strive await Auth.auth().signIn(with: oAuthCredential)
} catch {
Utils.showErrorAlert(viewController: self, message: error.localizedDescription)
}
}
}
}

