@mapcreator/api 3.3.4 → 3.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/Mapcreator.js +16 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapcreator/api",
3
- "version": "3.3.4",
3
+ "version": "3.3.5",
4
4
  "description": "Mapcreator JavaScript API",
5
5
  "main": "dist/bundle.js",
6
6
  "repository": "https://gitlab.com/mapcreator/api-wrapper.git",
package/src/Mapcreator.js CHANGED
@@ -223,7 +223,22 @@ export default class Mapcreator extends mix(EventEmitter, Injectable) {
223
223
 
224
224
  const hooks = {
225
225
  beforeRequest: [
226
- request => {
226
+ async request => {
227
+ // Get CSRF token before making the request
228
+ await fetch(`${this.host}/sanctum/csrf-cookie`, {
229
+ credentials: 'include'
230
+ });
231
+
232
+ // Get the XSRF token from cookies
233
+ const xsrfToken = document.cookie
234
+ .split('; ')
235
+ .find(row => row.startsWith('XSRF-TOKEN='))
236
+ ?.split('=')[1];
237
+
238
+ if (xsrfToken) {
239
+ request.headers.set('X-XSRF-TOKEN', decodeURIComponent(xsrfToken));
240
+ }
241
+
227
242
  if (this.authenticated) {
228
243
  request.headers.set('Authorization', this.auth.token.toString());
229
244
  }