fix: include cookies for fetch request

This commit is contained in:
grandeljay 2023-12-18 16:08:36 +01:00
parent 229d04eb07
commit 0a667b312d
6 changed files with 75 additions and 34 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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) {

View file

@ -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)