Skip to content

Commit 91a8850

Browse files
committed
fix: fetch token using @nextcloud/auth which updates the token on context
When a new token needs to be fetched we should use the function from the library which automatically also sets the new token on the current context (global state). It also handles calling the on-token-update events. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 2d7a46d commit 91a8850

3 files changed

Lines changed: 455 additions & 358 deletions

File tree

lib/interceptors/csrf-token.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import type { CancelableAxiosInstance } from '../client.ts'
77
import type { InterceptorErrorHandler } from './index.ts'
88

9-
import { generateUrl } from '@nextcloud/router'
9+
import { fetchRequestToken } from '@nextcloud/auth'
1010
import { isAxiosError } from 'axios'
1111

1212
const RETRY_KEY = Symbol('csrf-retry')
@@ -31,8 +31,7 @@ export function onCsrfTokenError(axios: CancelableAxiosInstance): InterceptorErr
3131
&& response?.data?.message === 'CSRF check failed') {
3232
console.warn(`Request to ${responseURL} failed because of a CSRF mismatch. Fetching a new token`)
3333

34-
const { data: { token } } = await axios.get(generateUrl('/csrftoken'))
35-
console.debug(`New request token ${token} fetched`)
34+
const token = await fetchRequestToken()
3635
axios.defaults.headers.requesttoken = token
3736

3837
return axios({

0 commit comments

Comments
 (0)