类型'AuthDataResult'的值没有成员'providerID'Firebase 5.0

时间:2018-07-30 08:31:11

标签: ios firebase firebase-authentication

我对最新版本的FirebaseAuth 5.0有疑问 这是我的代码:

func registerUser (withEmail email: String, andPassword password: String, userCreationComplete: @escaping (_ status: Bool, _ error: Error?) -> ()){
    Auth.auth().createUser(withEmail: email, password: password) { (user, error) in
        guard let user = user else{
            userCreationComplete(false, error)
            return
        }
        let userData = ["provider": user.providerID, "email": user.email]
        DataService.instance.createDBUser(uid: user.uid, userData: userData)
        userCreationComplete(true, nil)
    }

}

问题是“类型'AuthDataResult'的值没有值“ ProviderID”“但在Firebase 4中,此方法有效。谢谢!

2 个答案:

答案 0 :(得分:2)

根据reference docscreateUser函数使用(FIRAuthDataResult?, Error?)传递完成块。 FirAuthDataResultUser不同,但是它具有User作为属性,可以这样访问:

func registerUser (withEmail email: String, andPassword password: String, userCreationComplete: @escaping (_ status: Bool, _ error: Error?) -> ()){
    Auth.auth().createUser(withEmail: email, password: password) { (authResult, error) in
        guard let user = authResult.user else {
            userCreationComplete(false, error)
            return
        }
        let userData = ["provider": user.providerID, "email": user.email]
        DataService.instance.createDBUser(uid: user.uid, userData: userData)
        userCreationComplete(true, nil)
    }
}

答案 1 :(得分:0)

func registerUser(withEmail email: String, andPassword password: String, userCreationComplete: @escaping (_ status: Bool, _ error: Error?) -> ()) {
    Auth.auth().createUser(withEmail: email, password: password) { (authResult, error) in
        guard let user = authResult?.user else {
            userCreationComplete(false, error)
            return
        }

        let userData = ["provider": user.providerID, "email": user.email]
        DataService.instance.createDBUser(uid: user.uid, userData: userData)
        userCreationComplete(true, nil)
    }
}