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
Prepare for Segue with Array - Xcode 8.0 Swift 3.0
How to Notify a Queue in Swift (Gcd)
How to Implement Multiple Pangestures (Draggable Views)
Swift Updating Screen in Between Steps of While Loop
Show Datepicker Hourandminute on Print Statement Swiftui
Array Search Function Not Working in Swift
How to Use Dispatchgroup/Gcd to Execute Functions Sequentially in Swift
Xcode 8.0 Cbcentralmanager Issue
Arkit Setting Worldtrackingconfiguration to Gravityandheading Produces Error
Swift Uitableviewautomaticdimension Is Not Working
Updating Switfui View When Coredata Changes
Failable Initializers with Codable
How to Use Core Data Value from Picker? #Swiftui #Coredata
Var Declaration with Type VS Without
Custom Cell with Uitableview Inside Uicollectionviewcell
Error While Using Property 'Cgrectgetwidth', It Says It Was Replaced with 'Cgrect.Width'