Start a new topic
Answered

Error enum should support .unauthenticated value

I'm posting here as feedback for the Kinvey iOS dev team asking that the feature below be added as it's a scenario which doesn't appear to be covered by the SDK and to see if someone has a better solution.


Test case

- I have user who has created a new account.

- On Kinvey portal all new user accounts require email verification.

- The user received the email and deleted it without clicking the link to activate the account (or the user never received email for whatever reason).

- When that user tries to log in the an error of .unauthorized is received.

- In the description the error is " This app requires email address verification. Before performing any operations, please verify your email address by clicking the link sent to you upon signup.”


If I try to detect for the case above I have to look for the .unauthorized error. After I get that error I think have to look at the description string to see if it’s a bad username and password problem or if it’s a user who hasn’t clicked the link to authenticate the account.


This is a request to add a new “.unauthenticated” error to make it easy to check for the above condition. Below is a copy of code that I currently use to try and check and validate when the user tries to log in:


 @IBAction func login(_ sender: AnyObject) {

 if ((emailTextField.text?.characters.count)! == 0) || ((passwordTextField.text?.characters.count)! == 0) {

 showAlert(withTitle: "Missing Info", message: "Please enter your email and password.")

 } else {

 // Convert user name to lowercase since Kinvey is doing case sensitive matching, which we don't want.

 let userName = emailTextField.text!.lowercased()

 if userName.isValidEmail() == true {

 SVProgressHUD.show()

 

 User.login(username: userName, password: passwordTextField.text!) { user, error in

 SVProgressHUD.dismiss()

 if let user = user as? ScoreBookUser {

 self.userInfo = user

 self.performSegue(withIdentifier: self.LoginSuccessSegueID, sender: nil)

 } else if let kinveyError = error as? Kinvey.Error {

 switch kinveyError {

 case .methodNotAllowed:

 print("methodNotAllowed")

 case .dataLinkEntityNotFound:

 print("dataLinkEntityNotFound")

 case .unknownError:

 print("unknownError")

                            //                    case .unauthorized

                        //                        print("unauthorized")

 case .invalidOperation:

 print("invalidOperation")

 case .objectIdMissing:

 print("objectIdMissing")

 case .unknownJsonError:

 print("unknownJsonError")

 case .invalidResponse:

 print("invalidResponse")

 case .noActiveUser:

 print("noActiveUser")

 case .requestCancelled:

 print("requestCancelled")

 case .requestTimeout:

 print("requestTimeout")

 case .invalidDataStoreType:

 print("invalidDataStoreType")

 case .userWithoutEmailOrUsername:

 print("userWithoutEmailOrUsername")

 case .unauthorized(let response, let data, let error, let description):

 print("Response: \(response)") //401 statusCode also included here

 print("Data: \(String(data: data!, encoding: .utf8))")

 print("Error: \(error)")

 print("Description: \(description)")

 default:

 print("default")

 print("\(error)")

 }

 }

 }

 } else {

 showAlert(withTitle: "Email Invalid", message: "The email does not appear to be a valid email address. Please double check and try again.")

 }

 }

 }



Best Answer

Xavier,


An unverified user is an unauthorized user. When "Email Verification" option is enabled, you will not be able to create a new user that does not have an email address. If you don't click on the link of verification, your user will be unverified. There is already a way to detect this. You can check the status of the email verification for a user using following code.


 

let user = Kinvey.sharedClient.activeUser
let status = user?.metadata?.emailVerification?.status

 


Also, you can manually initiate email verification process.

http://devcenter.kinvey.com/ios/guides/users#emailverificationworkflow


Thanks,

Pranav

Kinvey



Hi Pranav. Thanks for your quick response. I already figured out how to do the check.  The issue I was reporting is that one of the returned error values should explicitly state the problem. When you make a call you have a list of possible errors why the user could not log in and you have a switch statement to catch those errors, but this specific issue isn't covered with the returned error types and it's more work to implement. This really is more of a feature request for the team. Thx.

Answer

Xavier,


An unverified user is an unauthorized user. When "Email Verification" option is enabled, you will not be able to create a new user that does not have an email address. If you don't click on the link of verification, your user will be unverified. There is already a way to detect this. You can check the status of the email verification for a user using following code.


 

let user = Kinvey.sharedClient.activeUser
let status = user?.metadata?.emailVerification?.status

 


Also, you can manually initiate email verification process.

http://devcenter.kinvey.com/ios/guides/users#emailverificationworkflow


Thanks,

Pranav

Kinvey


Login or Signup to post a comment