How can I avoid getting "This route can only be accessed by anonymous users"? 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};
axios.post('http://IP/user/login?_format=json',data_node)
  .then((response) =&gt; {
    console.log(response);
  })
  .catch((error) =&gt; {
    console.log(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?
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.