Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload with tus and cookie doesn't work #181

Open
boudafc opened this issue Apr 16, 2022 · 0 comments
Open

Upload with tus and cookie doesn't work #181

boudafc opened this issue Apr 16, 2022 · 0 comments

Comments

@boudafc
Copy link

boudafc commented Apr 16, 2022

Back-end: Laravel with Tus.io and Sanctum for authentication
Description:
Everything works with tus-js-client.
With vue-file-agent, everything work well when not using authentication, but when using authentication, the cookie (XSRF-TOKEN) is not added to the request. So then back-end return a "CSRF token mismatch." error.

My vue-agent-component:

<VueFileAgent
      ref="vueFileAgent"
      :theme="'grid'"
      :multiple="true"
      :deletable="true"
      :meta="true"
      :resumable="true"
      :maxFiles="14"
      :headers="headers"
      :uploadWithCredentials="true"
      :helpText="'Choose images or zip files'"
      :errorText="{
        type: 'Invalid file type. Only images or zip Allowed',
        size: 'Files should not exceed 10MB in size'
      }"
      @select="filesSelected($event)"
      @beforedelete="onBeforeDelete($event)"
      @delete="fileDeleted($event)"
      v-model="fileRecords"
    ></VueFileAgent>

Headers:

this.headers = {
      Accept: "application/json",
      "Access-Control-Allow-Credentials": "true",
      "X-XSRF-TOKEN": decodeURIComponent(this.getCookieValue("XSRF-TOKEN"))
    };

Function getCookieValue:

getCookieValue(a) {
      const b = document.cookie.match("(^|;)\\s*" + a + "\\s*=\\s*([^;]+)");
      return b ? b.pop() : "";
    },

Versions:
"tus-js-client": "^2.3.1",
"vue-file-agent": "^1.7.3",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant