RaspberryPiFoundation / editor-ui

Code Editor web component
https://editor-static.raspberrypi.org
Apache License 2.0
36 stars 9 forks source link

Logged-in UI state inconsistencies between app & web component #1050

Open floehopper opened 3 months ago

floehopper commented 3 months ago

If the user is logged in, but their access token in local storage has expired, it's possible for the logged-in UI state in the "outer" editor-standalone app to be different from that in the web component.

Steps to reproduce

  1. Clear all browser state / use private browser session
  2. Login
  3. Visit a "public" project, e.g. https://editor.raspberrypi.org/en/projects/blank-python-starter
  4. See that both the global nav UI and the web component "Save" button is in the logged-in state
  5. Expire/invalidate the access token in local storage by running a script in the browser console (see below)
  6. Refresh the project page
  7. See that the global nav UI is in the logged-out state, but the web component "Save" button is in the logged-in state (i.e. the button text does not say "Log in to save")
const authKey = localStorage.getItem("authKey");
const user = JSON.parse(localStorage.getItem(authKey));
const oneDayAgo = new Date().getTime() - 24 * 60 * 60 * 1000;
user.access_token = "invalid";
user.expires_at = oneDayAgo / 1000;
console.log(`expires at: ${new Date(oneDayAgo)}`);
localStorage.setItem(authKey, JSON.stringify(user));

Before access token expires

Image

After access token expires

Image

Notes

sra405 commented 3 months ago

I think this is caused by silent renewal not working in editor-standalone (fix here). I believe the web-component is doing its own silent renewal too (see the boolean in userManager) - potentially the cause of some of the CORP issues and it won't update because the object in localstorage isn't updating (due to the silent renewal issue) so the user object in the web-component isn't updating either Key bits: