Last active
November 2, 2022 23:36
-
-
Save toresbe/a8f4c94562c0cb3d222eb630f28ff560 to your computer and use it in GitHub Desktop.
Replacing withCredentials in use-tus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useTus } from "use-tus" | |
// withCredentials used to include credentials with use-tus. | |
// But the documentation to do so isn't totally obvious. | |
// Discussion: https://github.com/tus/tus-js-client/issues/167#issuecomment-623073224 | |
// Documentation: https://github.com/tus/tus-js-client/blob/14c3634e0ccd45973e90a3e460ca5e749f630107/docs/api.md | |
const { upload, setUpload } = useTus() | |
// Before, you could do this: | |
setUpload(file, { | |
withCredentials: true, | |
... | |
}) | |
// But withCredentials has been removed. Now I do this: | |
setUpload(file, { | |
onBeforeRequest: (req) => { | |
const xhr = req.getUnderlyingObject() as XMLHttpRequest | |
xhr.withCredentials = true | |
xhr.setRequestHeader("X-CSRF-Token", csrfToken) // not relevant to the use case, but possibly useful | |
}, | |
... | |
}) | |
// Hope this was useful to someone. :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment