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

问题描述 投票:0回答:1

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

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

然后我要求用户注册,并且我正在使用以下代码将匿名帐户链接到永久帐户:

    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
ios swift firebase firebase-authentication credentials
1个回答
0
投票
刚刚看到我的问题在哪里!代替这个:

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

我必须写这个:

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

一个小细节使我的代码停止工作
© www.soinside.com 2019 - 2024. All rights reserved.