Xcode Firebase | Cannot Convert Value of Type'Authdataresult' to Expected Argument Type 'User'

Xcode Firebase | Cannot convert value of type'AuthDataResult' to expected argument type 'User'

You need

Auth.auth().createUser(withEmail: email, password: password) { authResult, error in
// ...
guard let user = authResult.user else { reurn }
self.createProfile(user)
}

func createProfile(_ user: FIRUser ) { --- }

Cannot assign value of type 'AuthDataResult?' to type 'User?' and Value of type 'AuthDataResult' has no member 'uid'

You have understood it wrong, the completion handler is returning AuthDataResult? and Error. To get the value of user, you have to do this:

Auth.auth().signIn(withEmail: collectionTF[0].text!, password: collectionTF[1].text!, completion: { (authDataResult, error) in

if let error = error
{
print(error)

}
else
{
if let user = authDataResult?.user { //This is the user
currentUser = user
currentUserId = user.uid

completion(true)
}
}
}

This is how you can get the User from AuthDataResult.

Error reauthenticating user with Firebase / Xcode (for user email update)

I think you're missing the result parameter

let user = Auth.auth().currentUser
var credential: AuthCredential = EmailAuthProvider.credential(withEmail: "email", password: "pass")

user?.reauthenticate(with: credential) { result, error in
if let error = error {
// error handled here
} else {
// success
}
}

where result is an AuthDataResult that contains the result of a successful signin.



Related Topics



Leave a reply



Submit