Skip to content

Commit

Permalink
fix(requesttoken): Make sure to use the correct requesttoken in Webda…
Browse files Browse the repository at this point in the history
…vClient

Signed-off-by: Marcel Müller <marcel-mueller@gmx.de>

[skip ci]
  • Loading branch information
SystemKeeper authored and backportbot[bot] committed Jun 19, 2024
1 parent ff6666a commit 2249d46
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/services/WebdavClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@ import { createClient } from 'webdav'
import { getRootPath, getToken, isPublic } from '../utils/davUtils'
import { getRequestToken } from '@nextcloud/auth'

const headers = {
// Add this so the server knows it is an request from the browser
'X-Requested-With': 'XMLHttpRequest',
// Add the request token to the request
requesttoken: getRequestToken() || '',
// Use a method for the headers, to always get the current request token
const getHeaders = () => {
return {
// Add this so the server knows it is an request from the browser
'X-Requested-With': 'XMLHttpRequest',
// Add the request token to the request
requesttoken: getRequestToken() || '',
}
}

export const getClient = () => {
const client = createClient(getRootPath(), isPublic()
? { username: getToken(), password: '', headers }
: { headers },
? { username: getToken(), password: '', headers: getHeaders() }
: { headers: getHeaders() },
)

return client
Expand Down

0 comments on commit 2249d46

Please sign in to comment.