mirror of https://github.com/Lissy93/dashy.git
♻️ Slight refactor, before implementing Keycloak
This commit is contained in:
parent
7608fba2f5
commit
1bc27495d6
|
@ -16,24 +16,18 @@ import Minimal from '@/views/Minimal.vue';
|
||||||
import DownloadConfig from '@/views/DownloadConfig.vue';
|
import DownloadConfig from '@/views/DownloadConfig.vue';
|
||||||
|
|
||||||
// Import helper functions, config data and defaults
|
// 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 { config } from '@/utils/ConfigHelpers';
|
||||||
import { metaTagData, startingView, routePaths } from '@/utils/defaults';
|
import { metaTagData, startingView, routePaths } from '@/utils/defaults';
|
||||||
|
|
||||||
Vue.use(Router);
|
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 */
|
/* Returns true if user is already authenticated, or if auth is not enabled */
|
||||||
const isAuthenticated = () => {
|
const isAuthenticated = () => {
|
||||||
const auth = config.appConfig.auth || {};
|
const authEnabled = isAuthEnabled();
|
||||||
const users = Array.isArray(auth) ? auth : auth.users || [];
|
const userLoggedIn = isLoggedIn();
|
||||||
return (!users || users.length === 0 || isLoggedIn() || isGuestEnabled());
|
const guestEnabled = isGuestAccessEnabled();
|
||||||
|
return (!authEnabled || userLoggedIn || guestEnabled);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Get the users chosen starting view from app config, or return default */
|
/* Get the users chosen starting view from app config, or return default */
|
||||||
|
@ -99,7 +93,7 @@ const router = new Router({
|
||||||
},
|
},
|
||||||
beforeEnter: (to, from, next) => {
|
beforeEnter: (to, from, next) => {
|
||||||
// If the user already logged in + guest mode not enabled, then redirect home
|
// 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();
|
next();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue