我对最新版本的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中,此方法有效。谢谢!
答案 0 :(得分:2)
根据reference docs,createUser
函数使用(FIRAuthDataResult?, Error?)
传递完成块。 FirAuthDataResult
与User
不同,但是它具有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)
}
}