fix unauthorized recipe (#499)

This commit is contained in:
wengtad 2021-06-13 03:46:31 +08:00 committed by GitHub
parent 0e42f7407d
commit 562cea341b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 3 deletions

View File

@ -36,7 +36,8 @@ export const recipeAPI = {
async requestDetails(recipeSlug) { async requestDetails(recipeSlug) {
let response = await apiReq.get(API_ROUTES.recipesRecipeSlug(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) { updateImage(recipeSlug, fileObject, overrideSuccessMsg = false) {

View File

@ -193,6 +193,7 @@ export default {
} }
this.recipeDetails = await api.recipes.requestDetails(this.currentRecipe); this.recipeDetails = await api.recipes.requestDetails(this.currentRecipe);
if (!this.recipeDetails) router.push(`/login`);
this.skeleton = false; this.skeleton = false;
}, },
getImage(slug) { getImage(slug) {

View File

@ -27,7 +27,8 @@ export const recipeRoutes = [
meta: { meta: {
title: async route => { title: async route => {
const recipe = await api.recipes.requestDetails(route.params.recipe); const recipe = await api.recipes.requestDetails(route.params.recipe);
return recipe.name; if (recipe && recipe.name) return recipe.name;
else return null;
}, },
}, },
}, },