From 9bbac3b99e3168fc873467b510280ec4efc190d7 Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Mon, 12 Mar 2018 19:49:53 +0100 Subject: [PATCH] Handle HTTP auth for API calls --- cuizin/js_src/api.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cuizin/js_src/api.js b/cuizin/js_src/api.js index 174389b..e417f03 100644 --- a/cuizin/js_src/api.js +++ b/cuizin/js_src/api.js @@ -29,21 +29,22 @@ function _postProcessRecipes(response) { export function loadRecipes() { - return fetch(`${constants.API_URL}api/v1/recipes`) + return fetch(`${constants.API_URL}api/v1/recipes`, { credentials: 'same-origin' }) .then(_postProcessRecipes); } export function loadRecipe(id) { - return fetch(`${constants.API_URL}api/v1/recipe/${id}`) + return fetch(`${constants.API_URL}api/v1/recipe/${id}`, { credentials: 'same-origin' }) .then(_postProcessRecipes); } export function refetchRecipe(id) { - return fetch(`${constants.API_URL}api/v1/recipe/${id}/refetch`, { - method: 'GET', - }) + return fetch( + `${constants.API_URL}api/v1/recipe/${id}/refetch`, + { credentials: 'same-origin' }, + ) .then(_postProcessRecipes); } @@ -52,6 +53,7 @@ export function postRecipeByUrl(recipe) { return fetch(`${constants.API_URL}api/v1/recipes/by_url`, { method: 'POST', body: JSON.stringify(recipe), + credentials: 'same-origin', }) .then(_postProcessRecipes); } @@ -61,6 +63,7 @@ export function postRecipeManually(recipe) { return fetch(`${constants.API_URL}api/v1/recipes/manually`, { method: 'POST', body: JSON.stringify(recipe), + credentials: 'same-origin', }) .then(_postProcessRecipes); } @@ -70,6 +73,7 @@ export function editRecipe(id, recipe) { return fetch(`${constants.API_URL}api/v1/recipe/${id}`, { method: 'POST', body: JSON.stringify(recipe), + credentials: 'same-origin', }) .then(_postProcessRecipes); } @@ -78,5 +82,6 @@ export function editRecipe(id, recipe) { export function deleteRecipe(id) { return fetch(`${constants.API_URL}api/v1/recipe/${id}`, { method: 'DELETE', + credentials: 'same-origin', }); }