Firebase 将匿名帐户转换为永久帐户错误

Firebase Convert Anonymous to Permanent Account Error

我已经让用户通过以下代码在我的应用程序中匿名登录:

        Auth.auth().signInAnonymously { (result, error) in
            if let error = error {
                Auth.auth().handleFireAuthError(error: error, vc: self)
                debugPrint(error)
            }
        }

然后有一次我要求用户注册,我使用以下代码将匿名帐户 link 更改为永久帐户:

    guard let email = userEmailTextField.text, email.isNotEmpty,
        let password = userPasswordTextField.text, password.isNotEmpty else {
            simpleAlert(title: "Error", msg: "Please fill out all fields.")
            return
    }

    guard let confirmPass = userRepeatPasswordTextField.text , confirmPass == password else{
        simpleAlert(title: "Error", msg: "Passwords do not match.")
        return
    }

    guard let authUser = Auth.auth().currentUser else {
        return
    }

    let credential = EmailAuthProvider.credential(withEmail: email, link: password)

    authUser.link(with: credential) { (result, error) in

        if let error = error {
            debugPrint(error)
            Auth.auth().handleFireAuthError(error: error, vc: self)
            self.activityIndicator.stopAnimating()
            return
        }

        guard let fireUser = result?.user else {return}
        let artUser = User.init(id: fireUser.uid, email: email , stripeId:"")
        //Upload to Firestore
        self.createFirestoreUser(user: artUser)
    }

但是我在这里遇到了一个错误。我设置了断点,这是执行停止的地方 authUser.link(with: credential) { (result, error) in

这是我收到的错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSURLComponents initWithString:]: nil URLString parameter'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff23e39f0e __exceptionPreprocess + 350
    1   libobjc.A.dylib                     0x00007fff50ad79b2 objc_exception_throw + 48
    2   Foundation                          0x00007fff259659ca -[__NSConcreteURLComponents URL] + 0
    3   Foundation                          0x00007fff259673a8 +[NSURLComponents componentsWithString:] + 33
    4   Silobee                             0x000000010b144c52 +[FIRAuthWebUtils parseURL:] + 98
    5   Silobee                             0x000000010b16c638 __56-[FIRUser linkAndRetrieveDataWithCredential:completion:]_block_invoke_3 + 440
    6   Silobee                             0x000000010b16b084 __51-[FIRUser internalGetTokenForcingRefresh:callback:]_block_invoke + 340
    7   Silobee                             0x000000010b15df8c __65-[FIRSecureTokenService fetchAccessTokenForcingRefresh:callback:]_block_invoke + 156
    8   Silobee                             0x000000010b13fa7b __38-[FIRAuthSerialTaskQueue enqueueTask:]_block_invoke + 155
    9   libdispatch.dylib                   0x0000000110850f11 _dispatch_call_block_and_release + 12
    10  libdispatch.dylib                   0x0000000110851e8e _dispatch_client_callout + 8
    11  libdispatch.dylib                   0x00000001108586fd _dispatch_lane_serial_drain + 788
    12  libdispatch.dylib                   0x00000001108592c5 _dispatch_lane_invoke + 476
    13  libdispatch.dylib                   0x000000011085851c _dispatch_lane_serial_drain + 307
    14  libdispatch.dylib                   0x000000011085928f _dispatch_lane_invoke + 422
    15  libdispatch.dylib                   0x0000000110864b65 _dispatch_workloop_worker_thread + 719
    16  libsystem_pthread.dylib             0x00007fff51b37a3d _pthread_wqthread + 290
    17  libsystem_pthread.dylib             0x00007fff51b36b77 start_wqthread + 15
)
libc++abi.dylib: terminating with uncaught exception of type NSException

刚看到我的问题出在哪里!而不是这个:

let credential = EmailAuthProvider.credential(withEmail: email, link: password)

我不得不这样写:

let credential = EmailAuthProvider.credential(withEmail: email, password: password)

一个小细节导致我的代码无法运行