hrydgard / ppsspp-site

New PPSSPP website
60 stars 26 forks source link

Should clear localstorage userdata on any 401 #2

Closed hrydgard closed 1 year ago

hrydgard commented 1 year ago

To avoid weird states where you have to manually log out and log in again. Not sure how much these will occur in practice.

CarlosZBent commented 1 year ago

@hrydgard is this issue not already resolved in json_fetch.js?

function statusCodeAction(status, setUserData) {
  if (status == 401) {
    // If any API call returns Unauthorized, we'll simply
    // log out the user, since this should only ever happen if
    // (1) The user doesn't have the required status, in which case there might be something suspicious afoot
    // (2) The user login expired

    // Reset user data immediately
    if (setUserData) {
      console.log("401, logging out");
      setUserData(defaultUserContext);
      // Reset the local cookie so we don't auto-login on the next load.
      localStorage.removeItem('ppsspp-auth');
      // Reset the server cookie
      jsonPost("logout", null);
    } else {
      console.log("401, not logging out because !setUserData");
    }
  }
}

If not, what is required to fix this?

hrydgard commented 1 year ago

Yup, just forgot to close this.