Open
Description
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
- Clear all browser state / use private browser session
- Login
- Visit a "public" project, e.g. https://editor.raspberrypi.org/en/projects/blank-python-starter
- See that both the global nav UI and the web component "Save" button is in the logged-in state
- Expire/invalidate the access token in local storage by running a script in the browser console (see below)
- Refresh the project page
- 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
After access token expires
Notes
- Step 5 simulates a user closing the browser and coming back to the site over an hour later when their token will have expired.
- This problem is currently more significant, because the OIDC silent renewal isn't currently working.
- However, we think it highlights some shortcomings in the web component code which could still be an issue once the silent renewal is fixed.
- There is some useful context/info in this issue.
- We've now realised that these earlier changes were a bit of a bodge.
- The bodge works around the problem that if an API request is made (e.g. triggered by
useProject
) before the user has been set in the redux state (bylocalStorageUserMiddleware
), it's possible that the initial API request fails because it has an out-of-date access token and the API request is not retried even once the user has been set in the redux state.