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

我对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中这种方法有效。 谢谢!

根据参考文档 , createUser函数传递一个完成块(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) } }