diff options
author | Varun Patil <varunpatil@ucla.edu> | 2024-05-29 15:17:49 -0700 |
---|---|---|
committer | Christopher Ng <chrng8@gmail.com> | 2024-05-31 15:38:45 -0700 |
commit | 39ddfb07b59fba74d00a49194bdb16b521d01e6a (patch) | |
tree | 17329f3080a0a47056456c7817210e0d8fa3b687 /apps/files_versions | |
parent | 0f90cc97ca653a16f19769ba6d5c31a68196d136 (diff) | |
download | nextcloud-server-39ddfb07b59fba74d00a49194bdb16b521d01e6a.tar.gz nextcloud-server-39ddfb07b59fba74d00a49194bdb16b521d01e6a.zip |
fix(dav): multiple fixes in usage of webdav library
1. Refresh token on update
2. Fix some very weird imports
3. Patch fetch instead of request to prevent accessing impl details
Signed-off-by: Varun Patil <varunpatil@ucla.edu>
Diffstat (limited to 'apps/files_versions')
-rw-r--r-- | apps/files_versions/src/utils/davClient.js | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/apps/files_versions/src/utils/davClient.js b/apps/files_versions/src/utils/davClient.js index 022d34bbba4..b091935fc31 100644 --- a/apps/files_versions/src/utils/davClient.js +++ b/apps/files_versions/src/utils/davClient.js @@ -21,17 +21,25 @@ import { createClient } from 'webdav' import { generateRemoteUrl } from '@nextcloud/router' -import { getRequestToken } from '@nextcloud/auth' +import { getRequestToken, onRequestTokenUpdate } from '@nextcloud/auth' +// init webdav client const rootPath = 'dav' - -// init webdav client on default dav endpoint const remote = generateRemoteUrl(rootPath) -export default createClient(remote, { - headers: { - // Add this so the server knows it is an request from the browser - 'X-Requested-With': 'XMLHttpRequest', - // Inject user auth - requesttoken: getRequestToken() ?? '', - }, -}) +const client = createClient(remote) + +// set CSRF token header +const setHeaders = (token) => { + client.setHeaders({ + // Add this so the server knows it is an request from the browser + 'X-Requested-With': 'XMLHttpRequest', + // Inject user auth + requesttoken: token ?? '', + }) +} + +// refresh headers when request token changes +onRequestTokenUpdate(setHeaders) +setHeaders(getRequestToken()) + +export default client
\ No newline at end of file |