Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When unlink email account, Error Domain=FIRAuthErrorDomain Code=17016 "User was not linked to an account with the given provider." #3405

Closed
Hamada-Yuji opened this issue Jul 22, 2019 · 14 comments

Comments

@Hamada-Yuji
Copy link

commented Jul 22, 2019

Environment

  • Xcode version: 10.2.1
  • Firebase SDK version: 6.5.0
  • Firebase Component: Auth
  • Component version: 6.5.0
    *swift 5.0.1

I tried to unlink email account. like below code.

Auth.auth().currentUser?.unlink(fromProvider: EmailAuthProviderID) { (user, error) in
    if let error = error {
        print(error)
    }
}

but I got an error,

Error Domain=FIRAuthErrorDomain Code=17016 "User was not linked to an account with the given provider." UserInfo={NSLocalizedDescription=User was not linked to an account with the given provider., FIRAuthErrorUserInfoNameKey=ERROR_NO_SUCH_PROVIDER}

I also tried

let user = Auth.auth().currentUser!
let providerData = user.providerData
for provider in providerData {
    Auth.auth().currentUser?.unlink(fromProvider: provider.providerID) { (user, error) in
        if let error = error {
            print(error)
        }
    }
}

And I got the same error.
I tried to unlink after reauthenticate the email, but the same result.

GoogleAuthProviderID and FacebookAuthProviderID worked successfully, but only EmailAuthProviderID not worked.
How can I unlink EmailAuthProvider?

@morganchen12

This comment has been minimized.

Copy link
Collaborator

commented Jul 22, 2019

Is this the case for every user or just one user in particular?

@Hamada-Yuji

This comment has been minimized.

Copy link
Author

commented Jul 23, 2019

@morganchen12 Yes, I tried multiple accounts, But every user got the same error.

@Hamada-Yuji

This comment has been minimized.

Copy link
Author

commented Jul 23, 2019

I also tried on quickstart-ios/authentication/, and I got the same error.

I changed

  • GoogleService-Info.plist
  • Bundle Identifier
  • Associated Domains
  • actionCodeSettings.url

Is my Firebase account broken?

@morganchen12

This comment has been minimized.

Copy link
Collaborator

commented Jul 23, 2019

No, your Firebase account isn't broken; it's most likely a bug in Firebase Auth.

@renkelvin

This comment has been minimized.

Copy link
Collaborator

commented Jul 23, 2019

@Hamada-Yuji I'm not able to reproduce the issue. Could you share the full steps how to reproduce? (including how the user is created and linked)

@Hamada-Yuji

This comment has been minimized.

Copy link
Author

commented Jul 24, 2019

@renkelvin
In my code

// EmailLoginViewController.swift
@IBAction func sendAuth(_ sender: Any) {
  let actionCodeSettings = ActionCodeSettings()
  actionCodeSettings.url = URL(string: "https://www.example.com") // replace my own link
  actionCodeSettings.handleCodeInApp = true
  actionCodeSettings.setIOSBundleID(Bundle.main.bundleIdentifier!)
  Auth.auth().sendSignInLink(toEmail: mailTextField.text!, actionCodeSettings: actionCodeSettings) { error in

      if let error = error {
          print(error)
          return
      }
      UserDefaults.standard.set(self.mailTextField.text, forKey: "email")
  }
}
// AppDelegate.swift
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    guard let url = userActivity.webpageURL else { return true }
    let handled = DynamicLinks.dynamicLinks().handleUniversalLink(url) { [weak self] (link, _) in
        guard let linkURL = link?.url else { return }
        self?.handlePasswordlessSignIn(withURL: linkURL)
    }
    return handled
}

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
    if DynamicLinks.dynamicLinks().dynamicLink(fromCustomSchemeURL: url) != nil {
        // Handle the deep link. For example, show the deep-linked content or
        // apply a promotional offer to the user's account.
        return true
    }
    return false
}

func handlePasswordlessSignIn(withURL url: URL) {
    let link = url.absoluteString
    if Auth.auth().isSignIn(withEmailLink: link) {
            Auth.auth().signIn(withEmail: UserDefaults.standard.string(forKey: "email")!, link: link) { (result, error) in
                if let error = error {
                    print(error)
                    return
                }
            }
        }
    }
}
// AccountViewController.swift
@objc func unlinkMail() {
    Auth.auth().currentUser?.unlink(fromProvider: EmailAuthProviderID) { (user, error) in
        if let error = error {
            print(error) // found the error
        }
    }
}

This is my code.
And I also reproduce this issue on quickstart-ios/authentication/.
I wrote the steps above comment.

Are there any wrong steps?

@Hamada-Yuji

This comment has been minimized.

Copy link
Author

commented Jul 26, 2019

I debugged the sdk, and I found two problems here.

if ([provider isEqualToString:FIREmailAuthProviderID]) {
if (!self->_hasEmailPasswordCredential) {
completeAndCallbackWithError([FIRAuthErrorUtils noSuchProviderError]);
return;
}
setAccountInfoRequest.deleteAttributes = @[ FIRSetAccountInfoUserAttributePassword ];
} else {
if (!self->_providerData[provider]) {
completeAndCallbackWithError([FIRAuthErrorUtils noSuchProviderError]);
return;
}
setAccountInfoRequest.deleteProviders = @[ provider ];
}

  • _hasEmailPasswordCredential is always false. Maybe when Authenticate with Firebase Using Email Link, It doesn't have any password?
  • setAccountInfoRequest.deleteAttributes = @[ FIRSetAccountInfoUserAttributePassword ]; is not working. I tried setAccountInfoRequest.deleteAttributes = @[ FIRSetAccountInfoUserAttributeEmail ]; . It works

I feel it seems to be sdk bugs. Do you have any idea?

@renkelvin

This comment has been minimized.

Copy link
Collaborator

commented Jul 26, 2019

Fixed here: #3442

@paulb777 paulb777 added this to the 6.6.0 milestone Jul 28, 2019

@Hamada-Yuji

This comment has been minimized.

Copy link
Author

commented Jul 29, 2019

Thank you for fixing it, I found no error when I unlink email auth on iOS device.

But after I unlink email with this pull-request, I found the email auth on the firebase console, and I can log in with the email again. It seems to be not unlinked correctly.

Is it still fixing ( the server-side)?

@renkelvin

This comment has been minimized.

Copy link
Collaborator

commented Jul 29, 2019

Yeah, the server-side fix will be rolled out when Firebase v6.6.0 is released.

@paulb777

This comment has been minimized.

Copy link
Member

commented Aug 7, 2019

@renkelvin 6.6.0 is now published. Please confirm the server side fix has rolled out and close.

@renkelvin

This comment has been minimized.

Copy link
Collaborator

commented Aug 8, 2019

Unfortunately, the backend fix is delayed. I'll update here once it's available.

@paulb777 paulb777 removed this from the 6.6.0 milestone Aug 8, 2019

@Hamada-Yuji

This comment has been minimized.

Copy link
Author

commented Aug 16, 2019

@renkelvin how is backend release going?

@renkelvin

This comment has been minimized.

Copy link
Collaborator

commented Aug 16, 2019

@Hamada-Yuji It should be on prod from yesterday.

@paulb777 paulb777 closed this Aug 16, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.