firebase / FirebaseUI-iOS

iOS UI bindings for Firebase.
Apache License 2.0
1.51k stars 472 forks source link

Treat phone number like email in phone auth flow #547

Open entaku0818 opened 5 years ago

entaku0818 commented 5 years ago

Expected Results:

  1. Anonymous user can signup by phone number. This user become phone "number number user" and have a user info when anonymous user.
  2. Anonymous user can login by phone number, if phone number user was login in the past.

Relevant Code:

I think get Expected Results by the code below. However, I have a Expected Result 1 only. Why?

        let authUI: FUIAuth = FUIAuth.defaultAuthUI()!
        let authProvider: FUIAuthProvider = FUIPhoneAuth(authUI:authUI)
        authUI.providers = [authProvider]

        let phoneProvider: FUIPhoneAuth = authUI.providers.first as! FUIPhoneAuth

        phoneProvider.signIn(withDefaultValue: "", presenting:self) { (credential, error, callback) in

            if let error = error{
                print(error)
                return
            }

            if let credential = credential,let user = Auth.auth().currentUser {

                user.linkAndRetrieveData(with: credential) { (authResult, error) in
                    if let error = error {
                        print(error)
                        Auth.auth().signInAndRetrieveData(with: credential) { (result, error) in
                            if let error = error {
                                print(error)

                                return
                            }
                            self.navigationController?.dismiss(animated: true, completion: nil)

                        }
                        return
                    }
                    self.navigationController?.dismiss(animated: true, completion: nil)
                }

            }
        }

Reference

https://firebase.google.com/docs/auth/ios/account-linking

morganchen12 commented 5 years ago

What errors are you running into when trying this? Phone auth is currently experiencing some issues.

entaku0818 commented 5 years ago

Thank you for the response. This error message is below.

Error Domain=FIRAuthErrorDomain Code=17025 "This credential is already associated with a different user account." UserInfo={FIRAuthUpdatedCredentialKey=<FIRPhoneAuthCredential: 0x283d25470>, NSLocalizedDescription=This credential is already associated with a different user account., error_name=ERROR_CREDENTIAL_ALREADY_IN_USE}
Error Domain=FIRAuthErrorDomain Code=17051 "The SMS code has expired. Please re-send the verification code to try again." UserInfo={NSLocalizedDescription=The SMS code has expired. Please re-send the verification code to try again., error_name=ERROR_SESSION_EXPIRED}
morganchen12 commented 5 years ago

Looks like you're running into two errors.

entaku0818 commented 5 years ago

I know.

I wanted to make the following logic When that phone number was using "sign in", if it was not using "signup."

I guess it's hard I think it would be good for the user input to "sms code" again when that phone number was using.

Thank you your help.

MrSalman333 commented 4 years ago

I know.

I wanted to make the following logic When that phone number was using "sign in", if it was not using "signup."

I guess it's hard I think it would be good for the user input to "sms code" again when that phone number was using.

Thank you your help.

ran into the smae issue today ,

any updates?