diff options
author | Varun Patil <varunpatil@ucla.edu> | 2023-10-30 10:52:08 -0700 |
---|---|---|
committer | skjnldsv <skjnldsv@protonmail.com> | 2024-02-28 19:23:47 +0100 |
commit | b03fd6e363ef75ec69c5150b8992a838f724ce45 (patch) | |
tree | ebe8428c555863fbdcb3d477726995a661d66be8 /apps/files_trashbin | |
parent | dfd42307f04148f09a9f9811323178d4657fcc0a (diff) | |
download | nextcloud-server-b03fd6e363ef75ec69c5150b8992a838f724ce45.tar.gz nextcloud-server-b03fd6e363ef75ec69c5150b8992a838f724ce45.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_trashbin')
-rw-r--r-- | apps/files_trashbin/src/services/client.ts | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/apps/files_trashbin/src/services/client.ts b/apps/files_trashbin/src/services/client.ts index 9fb3361839a..e9ea06a9a5e 100644 --- a/apps/files_trashbin/src/services/client.ts +++ b/apps/files_trashbin/src/services/client.ts @@ -19,15 +19,28 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ + import { createClient } from 'webdav' import { generateRemoteUrl } from '@nextcloud/router' -import { getCurrentUser, getRequestToken } from '@nextcloud/auth' +import { getCurrentUser, getRequestToken, onRequestTokenUpdate } from '@nextcloud/auth' +// init webdav client export const rootPath = `/trashbin/${getCurrentUser()?.uid}/trash` export const rootUrl = generateRemoteUrl('dav' + rootPath) -const client = createClient(rootUrl, { - headers: { - requesttoken: getRequestToken(), - }, -}) +const client = createClient(rootUrl) + +// set CSRF token header +const setHeaders = (token: string | null) => { + 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 |