Handle HTTP auth for API calls

This commit is contained in:
Lucas Verney 2018-03-12 19:49:53 +01:00
parent 9813796a5d
commit 9bbac3b99e

View File

@ -29,21 +29,22 @@ function _postProcessRecipes(response) {
export function loadRecipes() { export function loadRecipes() {
return fetch(`${constants.API_URL}api/v1/recipes`) return fetch(`${constants.API_URL}api/v1/recipes`, { credentials: 'same-origin' })
.then(_postProcessRecipes); .then(_postProcessRecipes);
} }
export function loadRecipe(id) { 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); .then(_postProcessRecipes);
} }
export function refetchRecipe(id) { export function refetchRecipe(id) {
return fetch(`${constants.API_URL}api/v1/recipe/${id}/refetch`, { return fetch(
method: 'GET', `${constants.API_URL}api/v1/recipe/${id}/refetch`,
}) { credentials: 'same-origin' },
)
.then(_postProcessRecipes); .then(_postProcessRecipes);
} }
@ -52,6 +53,7 @@ export function postRecipeByUrl(recipe) {
return fetch(`${constants.API_URL}api/v1/recipes/by_url`, { return fetch(`${constants.API_URL}api/v1/recipes/by_url`, {
method: 'POST', method: 'POST',
body: JSON.stringify(recipe), body: JSON.stringify(recipe),
credentials: 'same-origin',
}) })
.then(_postProcessRecipes); .then(_postProcessRecipes);
} }
@ -61,6 +63,7 @@ export function postRecipeManually(recipe) {
return fetch(`${constants.API_URL}api/v1/recipes/manually`, { return fetch(`${constants.API_URL}api/v1/recipes/manually`, {
method: 'POST', method: 'POST',
body: JSON.stringify(recipe), body: JSON.stringify(recipe),
credentials: 'same-origin',
}) })
.then(_postProcessRecipes); .then(_postProcessRecipes);
} }
@ -70,6 +73,7 @@ export function editRecipe(id, recipe) {
return fetch(`${constants.API_URL}api/v1/recipe/${id}`, { return fetch(`${constants.API_URL}api/v1/recipe/${id}`, {
method: 'POST', method: 'POST',
body: JSON.stringify(recipe), body: JSON.stringify(recipe),
credentials: 'same-origin',
}) })
.then(_postProcessRecipes); .then(_postProcessRecipes);
} }
@ -78,5 +82,6 @@ export function editRecipe(id, recipe) {
export function deleteRecipe(id) { export function deleteRecipe(id) {
return fetch(`${constants.API_URL}api/v1/recipe/${id}`, { return fetch(`${constants.API_URL}api/v1/recipe/${id}`, {
method: 'DELETE', method: 'DELETE',
credentials: 'same-origin',
}); });
} }