From d2abff9324f06d3fee429b77746784d1444bd288 Mon Sep 17 00:00:00 2001 From: Janos Rusiczki Date: Thu, 21 Nov 2024 16:30:37 +0200 Subject: [PATCH] Fix unathorized upload and admin settings --- app/javascript/entrypoints/application.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/app/javascript/entrypoints/application.js b/app/javascript/entrypoints/application.js index 13ce211a..8faa8a16 100644 --- a/app/javascript/entrypoints/application.js +++ b/app/javascript/entrypoints/application.js @@ -41,8 +41,8 @@ document.addEventListener("DOMContentLoaded", () => { } }; - const redirectUnauthorized = (isAuthorized) => (to, from) => { - if (!isAuthorized) { + const redirectIfUnauthorized = (key) => (to, from) => { + if (!userStore[key]) { toaster("You are not authorized to access that page.", "is-warning"); return { name: "root" }; } @@ -104,19 +104,13 @@ document.addEventListener("DOMContentLoaded", () => { path: settings.users_admin_settings_path, name: "users-admin-settings", component: () => import("../users/admin-settings.vue"), - beforeEnter: [ - redirectIfNotSignedIn, - redirectUnauthorized(userStore.admin), - ], + beforeEnter: [redirectIfNotSignedIn, redirectIfUnauthorized("admin")], }, { path: settings.photos_path + "/upload", name: "photos-upload", component: () => import("../photos/upload.vue"), - beforeEnter: [ - redirectIfNotSignedIn, - redirectUnauthorized(userStore.uploader), - ], + beforeEnter: [redirectIfNotSignedIn, redirectIfUnauthorized("uploader")], }, { path: settings.photos_path + "/organizer",