类型'AuthDataResult'的值没有成员'providerID'Firebase 5.0 [英] Value of type 'AuthDataResult' has no member 'providerID' Firebase 5.0

查看:57
本文介绍了类型'AuthDataResult'的值没有成员'providerID'Firebase 5.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a problem with the newest version of FirebaseAuth 5.0 this is my code:

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中,此方法有效.谢谢!

problem is "Value of type 'AuthDataResult' has no value "ProviderID" " But in firebase 4 this method worked. Thanks!

推荐答案

根据

According to the reference docs, the createUser function passes a completion block with (FIRAuthDataResult?, Error?). FirAuthDataResult is not the same as a User, but it has a User as a property, which can be accessed like this:

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)
    }
}

这篇关于类型'AuthDataResult'的值没有成员'providerID'Firebase 5.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆