I'm trying to use REST login from a React native app. When the user tries to log in, the app calls:

var data_node = {name:this.state.username,pass:this.state.password};
  .then((response) => {
  .catch((error) => {

If the call succeds, in test, the next time I try to authenticate the user, I get this error because the user has been authenticated in a previous call for which I haven't saved data, so I cannot call user/logout.

This route can only be accessed by anonymous users.

How can I avoid it, forcing a new login?

  • 2
    Because the user already login. You have to logout and test again. – Jonh May 10 '19 at 9:47
  • 2
    Drupal won't be able to help you with this; unless you want to do it the proper way, i.e. logging out before attempting to log in again, you'll have to approach it from the axios point of view, and find a way to stop it sending the session credentials along with the second request. – Clive May 10 '19 at 10:01

This issue happens because you are trying to access the user/login route when you have cookie maintained at your app level. You need to make sure you clear the cookies before visiting that route.

You can use https://github.com/joeferraro/react-native-cookies to make sure all the cookies are cleared before you try to log in.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.