ERROR is value of type 'AuthDataResult' has no member 'uid'?
The error you get is:
Value of type
AuthDataResult
has no memberuid
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 ‘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
}
})
})
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
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]
Related Topics
Restrictions Around Protocols and Generics in Swift
Cllocationmanager and Tvos - Requestwheninuseauthorization() Not Prompting
In App Purchase in Skscene Not Working
Remove Cell When Button Pressed Inside Cell Customtableviewcell
How to Cut a Hole in a Sprite Image or Texture to Show What Is Behind It Using Spritekit in Swift
iOS Coredata Compatible with Both iOS 9 and iOS 10
Adding Data to a Specific UId in Firebase
Avoid Equatable and Hashable Boilerplate, Swift 4.2
Sklabelnode Text with Two Different Fonts and Colour. How Is This Possible
Sandbox Entitlement to Script Itunes via Nsapplescript
Got Error: Return an Empty String to Bool
How to Get User Nearby My Location in Geofire,Firebase
Where to Place Code for Audio Playback in a Swiftui App
Generate Random Questions in Swift
Error: Missing Return in a Closure Expected to Return 'Uiviewcontroller' (Xcode, Swift, iOS 13)
Nstimer Scheduledtimerwithtimeinterval and Target Is "Class Level Function"