fix: refactor request token handling and do not update with invalid result
- Resolves https://github.com/nextcloud/server/issues/40626
Summary
Originally this should have been only a refactoring to migrate the code to Typescript and add some more tests for it. But doing so I discovered some issues within the logic that revealed to cause the linked issue (or to cause at least the frontend part of it).
- If the request fails we should NOT update the token (do not emit an event!)
- if a invalid token is about to be set do not update it
- some issues noticed where we use the wrong types (e.g. local storage only works with strings).
The issue itself if likely to be orginally caused by some server issue (e.g. overloaded) which causes a 500 return, then we have an "undefined" token (as the old code did not check for the validity) and tried to update it. This causes all following requests to use an invalid token.
Checklist
- Code is properly formatted
- Sign-off message is added to all commits
- [x] Tests (unit, integration, api and/or acceptance) are included
- [x] Screenshots before/after for front-end changes
- [x] Documentation (manuals or wiki) has been updated or is not required
- [x] Backports requested where applicable (ex: critical bugfixes)
Best to review commit by commit - most changes are tests only.
/backport to stable31
/backport to stable30
/compile
Thank you for this! The linked bug has been present for years, I really hope this is the end of it.