feat: add setRequestToken and fetchRequestToken methods#900
feat: add setRequestToken and fetchRequestToken methods#900
setRequestToken and fetchRequestToken methods#900Conversation
cfc893c to
b7d9bc6
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #900 +/- ##
==========================================
+ Coverage 60.71% 65.75% +5.03%
==========================================
Files 4 4
Lines 56 73 +17
Branches 17 23 +6
==========================================
+ Hits 34 48 +14
- Misses 20 21 +1
- Partials 2 4 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| export function getRequestToken(): string | null { | ||
| if (globalThis.document) { | ||
| return document.head.dataset.requesttoken ?? null | ||
| } | ||
| // for service workers or other contexts without DOM, we keep the token in memory | ||
| return globalThis._nc_auth_requestToken ?? null | ||
| } |
There was a problem hiding this comment.
In the previous implementation it only used DOM API once to initiate the local state. Now every getRequestToken call gets it via DOM API.
What about checking _nc_auth_requestToken first and only as a fallback get it from the document to init the local state?
There was a problem hiding this comment.
Then we still have a problem if updated outside of this library (aka old server versions).
There was a problem hiding this comment.
(I mean we can do so and hope to update server in time - but still wonder how much overhead the DOM API call would be here)
There was a problem hiding this comment.
- If we change the token here in an app A
- Then another app B causes a token change in server
- Now this app A tries to get the token and gets the outdated because server only updated the DOM
- App A needs 2 useless requests to recover
There was a problem hiding this comment.
Doesn't setToken on server emit the event even on a very old server?
nextcloud/server#17404
There was a problem hiding this comment.
Ah yes seems to work.
There was a problem hiding this comment.
I have adjusted the implementation to use the cached version if possible.
Also prevented an event loop
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Basically move them from server to this library, implementation only slightly changed for the non-dom case to keep service worker support. Otherwise same implementation and even tests are copied.
This allows us to have 1 place with the
set tokenlogic to reduce problems where the tokens get out of sync.