How to verify a user's email address on iOS with Firebase?

前端 未结 2 1214
死守一世寂寞
死守一世寂寞 2021-02-01 11:12

I\'m stuck with email verification with firebase. I\'ve looked around for guidance but no help. After the user verifies his email, my code still prints out the user has not been

2条回答
  •  抹茶落季
    2021-02-01 11:48

    You are using the coalescing operator after FIRAuth.auth() which means the following method call will return nil when FIRAuth.auth() was nil. If this is the case, your comparison with true will fail, since nil is not true.

    I suggest you to refactor your code like this for easier debugging:

    guard let auth = FIRAuth.auth(), user = auth.currentUser else {
        print("No auth / user")
    }
    
    guard user.emailVerified else {
        print("Email not verified")
        return
    }
    
    guard let email = email.text, password = passsword.text else {
        print("No email or password")
        return
    }
    
    auth.signInWithEmail(email, password: password) { user, error in
        if let error = error {
            print("Email/password is wrong or user does not exist, error: \(error)")
        } else {
            print("Successful login.")
        }
    }
    

    You should find your error easier like this.

提交回复
热议问题