From 0a667b312dbad2b0ecb6482e7a30a5c2fb5e19b7 Mon Sep 17 00:00:00 2001 From: grandeljay Date: Mon, 18 Dec 2023 16:08:36 +0100 Subject: [PATCH] fix: include cookies for fetch request --- src/assets/js/home.js | 6 ++++-- src/assets/js/html2canvas.js | 5 +++-- src/assets/js/install.js | 5 +++-- src/assets/js/parts/wish.js | 36 +++++++++++++++++++++++--------- src/assets/js/parts/wishlists.js | 36 +++++++++++++++++++++----------- src/assets/js/wishlist.js | 21 +++++++++++++------ 6 files changed, 75 insertions(+), 34 deletions(-) diff --git a/src/assets/js/home.js b/src/assets/js/home.js index e37d26cf..0841ddc6 100644 --- a/src/assets/js/home.js +++ b/src/assets/js/home.js @@ -3,7 +3,8 @@ $(function() { * Statistics */ fetch('/index.php?page=api&module=statistics&table=all', { - method: 'GET' + method : 'GET', + credentials : 'include', }) .then(handleFetchError) .then(handleFetchResponse) @@ -57,7 +58,8 @@ $(function() { * News */ fetch('/index.php?page=api&module=blog', { - method: 'GET' + method : 'GET', + credentials : 'include', }) .then(handleFetchError) .then(handleFetchResponse) diff --git a/src/assets/js/html2canvas.js b/src/assets/js/html2canvas.js index 7c5cb9fe..fc1fd1b6 100644 --- a/src/assets/js/html2canvas.js +++ b/src/assets/js/html2canvas.js @@ -21,8 +21,9 @@ window.addEventListener("load", (event) => { /** Save page preview */ fetch('/index.php?page=api&module=save-preview', { - method : 'POST', - body : data + method : 'POST', + credentials : 'include', + body : data, }) .then(handleFetchError) .then(handleFetchResponse) diff --git a/src/assets/js/install.js b/src/assets/js/install.js index c1dd88fc..9996d78a 100644 --- a/src/assets/js/install.js +++ b/src/assets/js/install.js @@ -10,8 +10,9 @@ $(function() { form.addClass('loading'); fetch('/index.php?page=api&module=database-test', { - method : 'POST', - body : formDatabase + method : 'POST', + credentials : 'include', + body : formDatabase, }) .then(handleFetchError) .then(handleFetchResponse) diff --git a/src/assets/js/parts/wish.js b/src/assets/js/parts/wish.js index 97352a07..82d7a4e5 100644 --- a/src/assets/js/parts/wish.js +++ b/src/assets/js/parts/wish.js @@ -93,7 +93,13 @@ $(function () { } ); - fetch('/index.php?' + get_wish, { method: 'GET' }) + fetch( + '/index.php?' + get_wish, + { + method : 'GET', + credentials : 'include', + } + ) .then(handleFetchError) .then(handleFetchResponse) .then(function(response) { @@ -110,7 +116,13 @@ $(function () { var wish_image_ext = wish_image.split('.').pop(); if ('svg' === wish_image_ext) { - fetch(wish_image, { method: 'GET' }) + fetch( + wish_image, + { + method : 'GET', + credentials : 'include', + } + ) .then(handleFetchError) .then(handleFetchResponse) .then(function(response) { @@ -138,8 +150,9 @@ $(function () { $(document).on('click', wish_button_mark_as_fulfilled, function() { const modal_wish_details = $(this).closest('.ui.modal'); const mark_as_fulfilled = { - 'method' : 'PUT', - 'body' : new URLSearchParams({ + 'method' : 'PUT', + 'credentials' : 'include', + 'body' : new URLSearchParams({ 'wish_id' : wish.id, 'wish_status' : wishthis.wish.status.fulfilled, }), @@ -168,8 +181,9 @@ $(function () { $(document).on('click', wish_button_fulfil_wish, function() { const modal_wish_details = $(this).closest('.ui.modal'); const mark_as_fulfilled = { - 'method' : 'PUT', - 'body' : new URLSearchParams({ + 'method' : 'PUT', + 'credentials' : 'include', + 'body' : new URLSearchParams({ 'wish_id' : wish.id, 'wish_status' : wishthis.wish.status.unavailable, }), @@ -278,8 +292,9 @@ $(function () { ); fetch('/index.php?page=api&module=wishes', { - 'method' : 'POST', - 'body' : wish_data, + 'method' : 'POST', + 'credentials' : 'include', + 'body' : wish_data, }) .then(handleFetchError) .then(handleFetchResponse) @@ -336,8 +351,9 @@ $(function () { }); fetch('/index.php?page=api&module=wishes', { - 'method' : 'DELETE', - 'body' : wish_delete, + 'method' : 'DELETE', + 'credentials' : 'include', + 'body' : wish_delete, }) .then(handleFetchError) .then(handleFetchResponse) diff --git a/src/assets/js/parts/wishlists.js b/src/assets/js/parts/wishlists.js index 11dfefb7..8b0daf56 100644 --- a/src/assets/js/parts/wishlists.js +++ b/src/assets/js/parts/wishlists.js @@ -142,8 +142,9 @@ $(function () { formData.append('wishlist_id', wishthis.$_GET.id); fetch('/index.php?page=api&module=wishlists', { - method : 'PUT', - body : formData, + method : 'PUT', + credentials : 'include', + body : formData, }) .then(handleFetchError) .then(handleFetchResponse) @@ -224,8 +225,9 @@ $(function () { } ); fetch('/index.php?page=api&module=wishlists', { - 'method' : 'DELETE', - 'body' : delete_wishlist, + 'method' : 'DELETE', + 'credentials' : 'include', + 'body' : delete_wishlist, }) .then(handleFetchError) .then(handleFetchResponse) @@ -331,8 +333,9 @@ $(function () { var formData = new URLSearchParams(new FormData(formWishlistCreate[0])); fetch('/index.php?page=api&module=wishlists', { - method : 'POST', - body : formData + method : 'POST', + credentials : 'include', + body : formData }) .then(handleFetchError) .then(handleFetchResponse) @@ -395,7 +398,8 @@ $(function () { ); fetch('/index.php?' + params_url, { - method: 'GET' + method : 'GET', + credentials : 'include', }) .then(handleFetchError) .then(handleFetchResponse) @@ -432,8 +436,9 @@ $(function () { ); fetch('/index.php?page=api&module=wishes', { - method : 'PUT', - body : formData + method : 'PUT', + credentials : 'include', + body : formData }) .then(handleFetchError) .then(handleFetchResponse) @@ -468,8 +473,9 @@ $(function () { formData.append('wishlist_id', wishthis.$_GET.id); fetch('/index.php?page=api&module=wishes', { - 'method' : 'POST', - 'body' : formData, + 'method' : 'POST', + 'credentials' : 'include', + 'body' : formData, }) .then(handleFetchError) .then(handleFetchResponse) @@ -495,7 +501,13 @@ $(function () { * Update URL */ function updateURL() { - fetch('/index.php?page=api&module=url&url=' + window.btoa('/?' + urlParams.toString()), { method: 'GET' }) + fetch( + '/index.php?page=api&module=url&url=' + window.btoa('/?' + urlParams.toString()), + { + method : 'GET', + credentials : 'include', + } + ) .then(handleFetchError) .then(handleFetchResponse) .then(function(response) { diff --git a/src/assets/js/wishlist.js b/src/assets/js/wishlist.js index c1415599..7c294f70 100644 --- a/src/assets/js/wishlist.js +++ b/src/assets/js/wishlist.js @@ -38,7 +38,13 @@ $(function() { if (!wishlist && wishthis.$_GET.hash) { var wishlistId = $('.wishlist-cards[data-wishlist]').attr('data-wishlist'); - fetch('/index.php?page=api&module=wishlists&id=' + wishlistId, { method: 'GET' }) + fetch( + '/index.php?page=api&module=wishlists&id=' + wishlistId, + { + method : 'GET', + credentials : 'include', + } + ) .then(handleFetchError) .then(handleFetchResponse) .then(function(response) { @@ -105,8 +111,9 @@ $(function() { ); fetch('/index.php?page=api&module=wishlists-saved', { - method : 'POST', - body : formData + method : 'POST', + credentials : 'include', + body : formData }) .then(handleFetchError) .then(handleFetchResponse) @@ -128,7 +135,8 @@ $(function() { /** Determine if list is saved */ fetch('/index.php?page=api&module=wishlists-saved', { - method : 'GET', + method : 'GET', + credentials : 'include', }) .then(handleFetchError) .then(handleFetchResponse) @@ -176,8 +184,9 @@ $(function() { buttonRequest.addClass('disabled loading'); fetch('/index.php?page=api&module=wishlists', { - method : 'POST', - body : formData + method : 'POST', + credentials : 'include', + body : formData }) .then(handleFetchError) .then(handleFetchResponse)