I am using Sign In With Apple and Email/passsword based login for which below are truncated code snippets.
In Apple signing in, i am getting error “This user is not allowed to query email on class _User” when i try to query on PFUser whether a user with the associated email is already registered.
Same query under email based method doesn’t fail.
What could be the reason?
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
switch authorization.credential {
case let credentials as ASAuthorizationAppleIDCredential:
let appleCredentialUserId = credentials.user //use as social_id
//check whether _User with this id already exits, if so login with it.
//MARK : this query works
CommonHelper.findSocialUser(for: appleCredentialUserId) { (user, error) in
if error == nil && user != nil {
//MARK: Login existing Apple user
//Account exists with Apple auth and this social id so login to parse
let authData = ["token":idTokenString!, "id": appleCredentialUserId]
self.loginWith(authType: "apple", using: authData) { (loggedInUser, error) in
//Post login view
} else if error != nil {
} //self.loginWith(authType: "apple",
} else if error == nil && user == nil {
let queryToCheckEmailTaken = PFUser.query()
queryToCheckEmailTaken?.whereKey("email", equalTo: credentials.email!)
//search if account already exists with selected email id.
//if doesnt exist then perform registration else login
//MARK: This fails
queryToCheckEmailTaken?.findObjectsInBackground(block: { (objects, error) in
} else if error != nil {
CommonHelper.showMessage(messageBody: "Could not login. Please try again.")
}
}
}
break
}
func loginWithEmail(_ sender: Any) {
// check whether account with same email exists
// if yes then error else login
let query = PFUser.query()
query?.whereKey("email", equalTo: emailToLoginWith)
query?.whereKey("login_provider", notEqualTo: "email")
//MARk: This works
query?.getFirstObjectInBackground(block: { (user, error) in
if error == nil && user != nil {
CommonHelper.showMessage(messageBody: "This mail is already being used by another user.",)
} else {
// go ahead with login
PFUser.logInWithUsername(inBackground: emailToLoginWith, password: self.passwordTextField.text!) {
(user, error) in
}
}
})
}