17 C
Canberra
Monday, January 5, 2026

Tips on how to keep away from "zombie" Firebase nameless customers when linking Check in with Apple?


I used to be questioning what could be a stable movement 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 consumer:

Auth.auth().signInAnonymously

And the next code to signal out:

Auth.auth().signOut

To hyperlink an nameless consumer with an Apple account, we use:

consumer.hyperlink(with: oAuthCredential)

Under is our present movement, which leads to a number of nameless customers being created for a single machine.

  1. On the sign-in web page, the consumer faucets "Proceed as visitor" -> the primary nameless consumer is created.

  2. On the primary app web page, the consumer faucets "Proceed with Apple" -> the nameless consumer is linked to the Apple account.

  3. The consumer faucets “Signal out”.

  4. On the sign-in web page, the consumer faucets "Proceed as visitor" once more -> a second nameless consumer is created.

  5. On the primary app web page, the consumer faucets "Proceed with Apple". Because the Apple account is already linked to the primary consumer, Firebase indicators the consumer again in as the primary consumer.

  6. Consequently, the second nameless consumer turns into a “zombie” consumer.

If steps 3-5 are repeated, extra "zombie" nameless customers will proceed to be created, as proven within the screenshot.

Tips on how to keep away from "zombie" Firebase nameless customers when linking Check in with Apple?

My query is: what’s a stable and advisable movement to forestall this example?

func updateBasedOnLoginStatus() {
    if let consumer = Auth.auth().currentUser, consumer.isAnonymous {
        // Present Apple join button, disguise signal out button.
        appleSignUpButton.isHidden = false
        signOutButton.isHidden = true
    } else {
        // Conceal 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
personal func handleOAuthCredentialAsync(_ oAuthCredential: OAuthCredential) {
    Activity {
        defer {
            updateBasedOnLoginStatus()
        }
        
        if let consumer = Auth.auth().currentUser, consumer.isAnonymous {
            do {
                _ = strive await consumer.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 consumer to login consumer.
            
            do {
                _ = strive await Auth.auth().signIn(with: oAuthCredential)
            } catch {
                Utils.showErrorAlert(viewController: self, message: error.localizedDescription)
            }
        }
    }
}

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles