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 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 '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
Apply Vertical Alpha Gradient to Uitableview
How to Display Realm Results in Swiftui List
What Is the Advantage of a Lazy Var in Swift
Extend Existing Protocols to Implement Another Protocol with Default Implements
How to Conform to Nscopying and Implement Copywithzone in Swift 2
In Swift, How to Have a Uiscrollview Subclass That Has an Internal and External Delegate
Dynamically Change Text of Realitykit Entity
Core Data: Failed to Load Model
Iso8601 Date JSON Decoding Using Swift4
Swift Convert String to Unsafemutablepointer<Int8>
Difference Between Using Objectidentifier() and '===' Operator
Keyboard Overlaying Action Sheet in iOS 13.1 on Cncontactviewcontroller
Swiftier Swift for 'Add to Array, or Create If Not There...'
Get Current Time as String Swift 3.0
Accessing Mkmapview Elements as Uiviewrepresentable in the Main (Contentview) Swiftui View
How to Limit Flatmap Concurrency in Combine Still Having All Source Events Processed