“Value of type 'AuthDataResult' has no member 'uid'” error

后端 未结 3 754
有刺的猬
有刺的猬 2020-12-16 19:15

Can someone help me about this issue? The first error was \"value of type \'authdataresult\' has no member \'uid\'\".

Auth.auth()?.signIn(withEmail: email, p         


        
相关标签:
3条回答
  • 2020-12-16 19:41
    guard let uid = user?.user.uid else {return}
    let ref = Database.database().reference(fromURL: "")
    let usersReference = ref.child("users").child(uid)
    
    0 讨论(0)
  • 2020-12-16 19:43

    The new Auth.auth().signIn and Auth.auth().createUser methods use a datatype of AuthDataResult? instead of User?

    The old callback was user of type: User?

    Auth.auth().signIn(withEmail: email, password: password, completion: { (user: User?, error) in
    

    You would access properties directly on the callback user object such as:

    if error == nil {
        if let user = user {
            self.userUid = user.uid
            // user.email for the email address in firebase
        }
    }
    

    The new callback is authDataResult of type: AuthDataResult?

    Auth.auth().signIn(withEmail: email, password: password, completion: { (authDataResult: AuthDataResult?, error) in
    

    Now you access properties directly on the callback authDataResult object such as:

    if error == nil {
        if let authDataResult = authDataResult {
            self.userUid = authDataResult.user.uid
            // authDataResult.user.email for the email address in firebase
        }
    }
    

    Basically the user object from the old way is now a property on the authDataResult object and you can get the uid through there:

    authDataResult.user.uid
    

    Firebase's info about AuthDataResult

    0 讨论(0)
  • 2020-12-16 19:49

    It seems that Google has made some changes to Firebase Auth with the 5.0.0 update. This worked for me:

    self.userUid = user.user.uid
    

    I'm not sure what was the point of the change but it still works exactly the same.

    0 讨论(0)
提交回复
热议问题