I just upgraded my pods for Firebase and got a ton of errors. I used the Docs on the Firebase Docs webpage so I was able to fix most of them. This error I'm stuck on and need some help please.
Here are my errors: (I marked them as Error 1. & Error 2.)
Cannot convert value of type '(User?, Error?) -> ()' to expected argument type 'AuthDataResultCallback?' (aka 'Optional<(Optional, Optional) -> ()>')
Value of type 'User?' has no member 'updateEmail'
Here is my AuthService.Swift code: (All the same Swift code, just split to show errors)
import Foundation
import Firebase
class AuthService {
static func signIn(email: String, password: String, onSuccess: @escaping () -> Void, onError: @escaping (_ errorMessage: String?) -> Void) {
Auth.auth().signIn(withEmail: email, password: password, completion: { (user, error) in
if error != nil {
onError(error!.localizedDescription)
return
}
onSuccess()
})
}
static func signUp(username: String, email: String, password: String, imageData: Data, onSuccess: @escaping () -> Void, onError: @escaping (_ errorMessage: String?) -> Void) {
Error 1.
Auth.auth().createUser(withEmail: email, password: password,
completion: { (user: User?, error: Error?) in
if error != nil {
onError(error!.localizedDescription)
return
}
let uid = user?.uid
let storageRef = FIRStorage.storage().reference(forURL: Config.STORAGE_ROOF_REF).child("profile_image").child(uid!)
storageRef.put(imageData, metadata: nil, completion: { (metadata, error) in
if error != nil {
return
}
let profileImageUrl = metadata?.downloadURL()?.absoluteString
self.setUserInfomation(profileImageUrl: profileImageUrl!, username: username, email: email, uid: uid!, onSuccess: onSuccess)
})
})
}
static func setUserInfomation(profileImageUrl: String, username: String, email: String, uid: String, onSuccess: @escaping () -> Void) {
let ref = Database.database().reference()
let usersReference = ref.child("users")
let newUserReference = usersReference.child(uid)
newUserReference.setValue(["username": username, "username_lowercase": username.lowercased(), "email": email, "profileImageUrl": profileImageUrl])
onSuccess()
}
static func updateUserInfor(username: String, email: String, imageData: Data, onSuccess: @escaping () -> Void, onError: @escaping (_ errorMessage: String?) -> Void) {
Error 2.
Api.User.CURRENT_USER.updateEmail(email, completion: { (error) in
if error != nil {
onError(error!.localizedDescription)
}else {
let uid = Api.User.CURRENT_USER?.uid
let storageRef = FIRStorage.storage().reference(forURL: Config.STORAGE_ROOF_REF).child("profile_image").child(uid!)
storageRef.put(imageData, metadata: nil, completion: { (metadata, error) in
if error != nil {
return
}
let profileImageUrl = metadata?.downloadURL()?.absoluteString
self.updateDatabase(profileImageUrl: profileImageUrl!, username: username, email: email, onSuccess: onSuccess, onError: onError)
})
}
})
}
static func updateDatabase(profileImageUrl: String, username: String, email: String, onSuccess: @escaping () -> Void, onError: @escaping (_ errorMessage: String?) -> Void) {
let dict = ["username": username, "username_lowercase": username.lowercased(), "email": email, "profileImageUrl": profileImageUrl]
Api.User.REF_CURRENT_USER?.updateChildValues(dict, withCompletionBlock: { (error, ref) in
if error != nil {
onError(error!.localizedDescription)
} else {
onSuccess()
}
})
}
static func logout(onSuccess: @escaping () -> Void, onError: @escaping (_ errorMessage: String?) -> Void) {
do {
try Auth.auth().signOut()
onSuccess()
} catch let logoutError {
onError(logoutError.localizedDescription)
}
}
}
See Question&Answers more detail:
os