Start a new topic
Answered

Invalid credentials (401) - Further requests denied

SDK: 3.3.8


During my development I got the following error, when trying to pull or find data from collections:

Invalid credentials. Please retry your request with correct credentials


I found one way to reproduce this error (and now I'm stuck):

In the backend:

  • Clear the User collection
  • Import a backup json into the User collection
  • => Every request is denied with the error message. 

Currently I'm stuck: Deleting & installing the App again seems not to solve this problem. Login with existing users is not possible anymore (same error). I must register/signup a new user.


Programmatically calling "Kinvey.sharedClient.activeUser?.logout()" is not solving the problem and I get the same error message, even when I recreate a new autogenerated user.


  1. I know, clearing the user collection is not usual, but: Are there other collection related tasks that can cause the "Invalid credentials" error?
  2. What is causing this "401 unauthorized" error? Is the SDK saving any session token in the keychain that are not valid anymore (and can not be deleted/recreated)?
  3. How to solve this problem in the App? What do I have to do (in code) to handle this error? 


Best Answer

"logout()" seems to work. My current solution:

if error.httpResponse?.statusCode == 401 {            
            Kinvey.sharedClient.activeUser?.logout()
            setupAutogeneratedUser()
}

func setupAutogeneratedUser() {
        if Kinvey.sharedClient.activeUser == nil  {
            User.signup { user, error in
         }
 }

 

1 Comment

Answer

"logout()" seems to work. My current solution:

if error.httpResponse?.statusCode == 401 {            
            Kinvey.sharedClient.activeUser?.logout()
            setupAutogeneratedUser()
}

func setupAutogeneratedUser() {
        if Kinvey.sharedClient.activeUser == nil  {
            User.signup { user, error in
         }
 }

 

Login or Signup to post a comment