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 * Statistics
*/ */
fetch('/index.php?page=api&module=statistics&table=all', { fetch('/index.php?page=api&module=statistics&table=all', {
method: 'GET' method : 'GET',
credentials : 'include',
}) })
.then(handleFetchError) .then(handleFetchError)
.then(handleFetchResponse) .then(handleFetchResponse)
@ -57,7 +58,8 @@ $(function() {
* News * News
*/ */
fetch('/index.php?page=api&module=blog', { fetch('/index.php?page=api&module=blog', {
method: 'GET' method : 'GET',
credentials : 'include',
}) })
.then(handleFetchError) .then(handleFetchError)
.then(handleFetchResponse) .then(handleFetchResponse)

View file

@ -22,7 +22,8 @@ window.addEventListener("load", (event) => {
/** Save page preview */ /** Save page preview */
fetch('/index.php?page=api&module=save-preview', { fetch('/index.php?page=api&module=save-preview', {
method : 'POST', method : 'POST',
body : data credentials : 'include',
body : data,
}) })
.then(handleFetchError) .then(handleFetchError)
.then(handleFetchResponse) .then(handleFetchResponse)

View file

@ -11,7 +11,8 @@ $(function() {
fetch('/index.php?page=api&module=database-test', { fetch('/index.php?page=api&module=database-test', {
method : 'POST', method : 'POST',
body : formDatabase credentials : 'include',
body : formDatabase,
}) })
.then(handleFetchError) .then(handleFetchError)
.then(handleFetchResponse) .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(handleFetchError)
.then(handleFetchResponse) .then(handleFetchResponse)
.then(function(response) { .then(function(response) {
@ -110,7 +116,13 @@ $(function () {
var wish_image_ext = wish_image.split('.').pop(); var wish_image_ext = wish_image.split('.').pop();
if ('svg' === wish_image_ext) { if ('svg' === wish_image_ext) {
fetch(wish_image, { method: 'GET' }) fetch(
wish_image,
{
method : 'GET',
credentials : 'include',
}
)
.then(handleFetchError) .then(handleFetchError)
.then(handleFetchResponse) .then(handleFetchResponse)
.then(function(response) { .then(function(response) {
@ -139,6 +151,7 @@ $(function () {
const modal_wish_details = $(this).closest('.ui.modal'); const modal_wish_details = $(this).closest('.ui.modal');
const mark_as_fulfilled = { const mark_as_fulfilled = {
'method' : 'PUT', 'method' : 'PUT',
'credentials' : 'include',
'body' : new URLSearchParams({ 'body' : new URLSearchParams({
'wish_id' : wish.id, 'wish_id' : wish.id,
'wish_status' : wishthis.wish.status.fulfilled, 'wish_status' : wishthis.wish.status.fulfilled,
@ -169,6 +182,7 @@ $(function () {
const modal_wish_details = $(this).closest('.ui.modal'); const modal_wish_details = $(this).closest('.ui.modal');
const mark_as_fulfilled = { const mark_as_fulfilled = {
'method' : 'PUT', 'method' : 'PUT',
'credentials' : 'include',
'body' : new URLSearchParams({ 'body' : new URLSearchParams({
'wish_id' : wish.id, 'wish_id' : wish.id,
'wish_status' : wishthis.wish.status.unavailable, 'wish_status' : wishthis.wish.status.unavailable,
@ -279,6 +293,7 @@ $(function () {
fetch('/index.php?page=api&module=wishes', { fetch('/index.php?page=api&module=wishes', {
'method' : 'POST', 'method' : 'POST',
'credentials' : 'include',
'body' : wish_data, 'body' : wish_data,
}) })
.then(handleFetchError) .then(handleFetchError)
@ -337,6 +352,7 @@ $(function () {
fetch('/index.php?page=api&module=wishes', { fetch('/index.php?page=api&module=wishes', {
'method' : 'DELETE', 'method' : 'DELETE',
'credentials' : 'include',
'body' : wish_delete, 'body' : wish_delete,
}) })
.then(handleFetchError) .then(handleFetchError)

View file

@ -143,6 +143,7 @@ $(function () {
fetch('/index.php?page=api&module=wishlists', { fetch('/index.php?page=api&module=wishlists', {
method : 'PUT', method : 'PUT',
credentials : 'include',
body : formData, body : formData,
}) })
.then(handleFetchError) .then(handleFetchError)
@ -225,6 +226,7 @@ $(function () {
); );
fetch('/index.php?page=api&module=wishlists', { fetch('/index.php?page=api&module=wishlists', {
'method' : 'DELETE', 'method' : 'DELETE',
'credentials' : 'include',
'body' : delete_wishlist, 'body' : delete_wishlist,
}) })
.then(handleFetchError) .then(handleFetchError)
@ -332,6 +334,7 @@ $(function () {
fetch('/index.php?page=api&module=wishlists', { fetch('/index.php?page=api&module=wishlists', {
method : 'POST', method : 'POST',
credentials : 'include',
body : formData body : formData
}) })
.then(handleFetchError) .then(handleFetchError)
@ -395,7 +398,8 @@ $(function () {
); );
fetch('/index.php?' + params_url, { fetch('/index.php?' + params_url, {
method: 'GET' method : 'GET',
credentials : 'include',
}) })
.then(handleFetchError) .then(handleFetchError)
.then(handleFetchResponse) .then(handleFetchResponse)
@ -433,6 +437,7 @@ $(function () {
fetch('/index.php?page=api&module=wishes', { fetch('/index.php?page=api&module=wishes', {
method : 'PUT', method : 'PUT',
credentials : 'include',
body : formData body : formData
}) })
.then(handleFetchError) .then(handleFetchError)
@ -469,6 +474,7 @@ $(function () {
fetch('/index.php?page=api&module=wishes', { fetch('/index.php?page=api&module=wishes', {
'method' : 'POST', 'method' : 'POST',
'credentials' : 'include',
'body' : formData, 'body' : formData,
}) })
.then(handleFetchError) .then(handleFetchError)
@ -495,7 +501,13 @@ $(function () {
* Update URL * Update URL
*/ */
function updateURL() { 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(handleFetchError)
.then(handleFetchResponse) .then(handleFetchResponse)
.then(function(response) { .then(function(response) {

View file

@ -38,7 +38,13 @@ $(function() {
if (!wishlist && wishthis.$_GET.hash) { if (!wishlist && wishthis.$_GET.hash) {
var wishlistId = $('.wishlist-cards[data-wishlist]').attr('data-wishlist'); 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(handleFetchError)
.then(handleFetchResponse) .then(handleFetchResponse)
.then(function(response) { .then(function(response) {
@ -106,6 +112,7 @@ $(function() {
fetch('/index.php?page=api&module=wishlists-saved', { fetch('/index.php?page=api&module=wishlists-saved', {
method : 'POST', method : 'POST',
credentials : 'include',
body : formData body : formData
}) })
.then(handleFetchError) .then(handleFetchError)
@ -129,6 +136,7 @@ $(function() {
/** Determine if list is saved */ /** Determine if list is saved */
fetch('/index.php?page=api&module=wishlists-saved', { fetch('/index.php?page=api&module=wishlists-saved', {
method : 'GET', method : 'GET',
credentials : 'include',
}) })
.then(handleFetchError) .then(handleFetchError)
.then(handleFetchResponse) .then(handleFetchResponse)
@ -177,6 +185,7 @@ $(function() {
fetch('/index.php?page=api&module=wishlists', { fetch('/index.php?page=api&module=wishlists', {
method : 'POST', method : 'POST',
credentials : 'include',
body : formData body : formData
}) })
.then(handleFetchError) .then(handleFetchError)