From 562cea341bac0783bf0d7d130e648627c29aa3df Mon Sep 17 00:00:00 2001 From: wengtad Date: Sun, 13 Jun 2021 03:46:31 +0800 Subject: [PATCH] fix unauthorized recipe (#499) --- frontend/src/api/recipe.js | 3 ++- frontend/src/pages/Recipe/ViewRecipe.vue | 3 ++- frontend/src/routes/recipes.js | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) 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; }, }, },