Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

:recycle: Slight refactor, before implementing Keycloak

Alicia Sykes1bc27495d6a6
diff --git a/src/router.js b/src/router.js
index 07c19273..1db8ceae 100644
--- a/src/router.js
+++ b/src/router.js
@@ -16,24 +16,18 @@ import Minimal from '@/views/Minimal.vue';
import DownloadConfig from '@/views/DownloadConfig.vue';
// Import helper functions, config data and defaults
-import { isLoggedIn } from '@/utils/Auth';
+import { isAuthEnabled, isLoggedIn, isGuestAccessEnabled } from '@/utils/Auth';
import { config } from '@/utils/ConfigHelpers';
import { metaTagData, startingView, routePaths } from '@/utils/defaults';
Vue.use(Router);
-/* Checks if guest mode is enabled in appConfig */
-const isGuestEnabled = () => {
- if (!config || !config.appConfig) return false;
- if (config.appConfig.enableGuestAccess) return true;
- return config.appConfig.auth.enableGuestAccess || false;
-};
-
/* Returns true if user is already authenticated, or if auth is not enabled */
const isAuthenticated = () => {
- const auth = config.appConfig.auth || {};
- const users = Array.isArray(auth) ? auth : auth.users || [];
- return (!users || users.length === 0 || isLoggedIn() || isGuestEnabled());
+ const authEnabled = isAuthEnabled();
+ const userLoggedIn = isLoggedIn();
+ const guestEnabled = isGuestAccessEnabled();
+ return (!authEnabled || userLoggedIn || guestEnabled);
};
/* Get the users chosen starting view from app config, or return default */
@@ -99,7 +93,7 @@ const router = new Router({
},
beforeEnter: (to, from, next) => {
// If the user already logged in + guest mode not enabled, then redirect home
- if (isAuthenticated() && !isGuestEnabled()) router.push({ path: '/' });
+ if (isAuthenticated() && !isGuestAccessEnabled()) router.push({ path: '/' });
next();
},
},