问题
OK here is the error I get:
1- When the app starts with phone1, user sign In Anonymously. Uid:ABC (link1)
2- phone1 user decides to login with Google Sign-In. User already has an Uid:ABC, so that User is converted from anonymous account to a permanent account with google sign-in. (link2)
3- With phone2, the app is launched first time and sign in Anonymously. Uid:ZYX (link1)
4- With phone2, user wants to login with same google account. So at this point using linkWithCredential cause "ERROR_CREDENTIAL_ALREADY_IN_USE". (link2)
So what is the proper solution for this issue?
回答1:
You are trying to link Two UIDs with Same Auth Credentials i.e with same google account. Which in itself is major security flaw and something that should never be done in a production app.
According to firebase official docs
ERROR_CREDENTIAL_ALREADY_IN_USE when trying to link a user with an AuthCredential corresponding to another account already in use
You should rather try to simply Sign - In and it will work. Your current action is equivalent to Sign - Up.
Please refer to these docs for proper google sign-in implementation. For your above procedure to work. You will first have to delete previous user so that old UID linked to the gmail account get's deleted.
Do let me know if this info helps you.
来源:https://stackoverflow.com/questions/39810626/firebase-how-to-handle-linkwithcredential-error-credential-already-in-use-in-a