"Value of Type 'Authdataresult' Has No Member 'Uid'" Error

Value of type 'AuthDataResult' has no member ‘uid’

According to the guide, when using .createUser,

If the new account was successfully created, the user is signed in,
and you can get the user's account data from the result object that's
passed to the callback method.

Notice in the sample, you get back authResult, not a User object. authResult contains some information, including the User. You can get to the User using authResult.user.

In addition, when calling the method, if successful, the user is already signed in, so there's no reason to sign them in again. I changed the parameter name to authResult from the sample to help eliminate some of the confusion.

Auth.auth().createUser(withEmail: email, password: password, completion: { authResult, error in
if let error = error {
// report error
return
}
guard let authResult = authResult else { return }
let firUser = authResult.user
let newUser = User(uid: firUser.uid, username: username, fullName: fullName, bio: "", website: "", follows: [], followedBy: [], profileImage: self.profileImage)
newUser.save(completion: { (error) in
if let error = error {
// report
} else {
// not sure what you need to do here anymore since the user is already signed in
}
})
})

ERROR is value of type 'AuthDataResult' has no member 'uid'?

The error you get is:

Value of type AuthDataResult has no member uid

If you look at the reference documentation for AuthDataResult, you'll see that this is correct: there is no uid in that class. The uid property exists in FIRUser, so you'll want to use:

user?.user.uid

Or to make it less confusing, give your current user variable a name that better matches what it is:

Auth.auth().signIn(withEmail: email, password: password) { (authData, error ) in
if error != nil{
//create account
} else {

KeychainWrapper.standard.set((authData?.user.uid)!,
forKey: ("Key_UID"))
self.preformSegue(performSegue(withIdentifier: "toFeed", sender: nil))
}
}

Value of type 'AuthDataResult' has no member 'providerID'

AuthDataResult has a property user that has providerID. You shouldn't consider AuthDataResult as user in the completion. You can access the providerId as below,

if let email = emailField.text, let password = passwordField.text {          
Auth.auth().signIn(withEmail: email, password: password) { (authData, error) in
if error == nil {
if let user = authData?.user {
if self.segmentedControl.selectedSegmentIndex == 0 {
let userData = ["provider": user.providerID] as [String: Any]

Value of type AuthDataResult has no member providerID

The problem is that object called user in the code isn't a FIRUser, it is an AuthDataResult as indicated by the error.

let authdataresult = // the thing you were calling user
let user = authdataresult.user // this is a FIRUser
let providerData = user.providerData // this is FIRUserInfo
let providerId = providerData.providerId


Related Topics



Leave a reply



Submit