diff --git a/frontend/src/api/recipe.js b/frontend/src/api/recipe.js index ed45e0ecda91..ac4e5fb86b4e 100644 --- a/frontend/src/api/recipe.js +++ b/frontend/src/api/recipe.js @@ -36,7 +36,8 @@ export const recipeAPI = { async requestDetails(recipeSlug) { let response = await apiReq.get(API_ROUTES.recipesRecipeSlug(recipeSlug)); - return response.data; + if (response && response.data) return response.data; + else return null; }, updateImage(recipeSlug, fileObject, overrideSuccessMsg = false) { diff --git a/frontend/src/pages/Recipe/ViewRecipe.vue b/frontend/src/pages/Recipe/ViewRecipe.vue index 5d31d433db73..6780985203ea 100644 --- a/frontend/src/pages/Recipe/ViewRecipe.vue +++ b/frontend/src/pages/Recipe/ViewRecipe.vue @@ -140,7 +140,7 @@ export default { }, watch: { - $route: function () { + $route: function() { this.getRecipeDetails(); this.checkPrintRecipe(); }, @@ -193,6 +193,7 @@ export default { } this.recipeDetails = await api.recipes.requestDetails(this.currentRecipe); + if (!this.recipeDetails) router.push(`/login`); this.skeleton = false; }, getImage(slug) { diff --git a/frontend/src/routes/recipes.js b/frontend/src/routes/recipes.js index 25140f3c6d8e..2aceec159e73 100644 --- a/frontend/src/routes/recipes.js +++ b/frontend/src/routes/recipes.js @@ -27,7 +27,8 @@ export const recipeRoutes = [ meta: { title: async route => { const recipe = await api.recipes.requestDetails(route.params.recipe); - return recipe.name; + if (recipe && recipe.name) return recipe.name; + else return null; }, }, },