Code improvments

This commit is contained in:
Alicia Sykes 2021-08-20 22:19:17 +01:00
parent 8df84252ac
commit 78e1fc6c94
2 changed files with 4 additions and 6 deletions

View File

@ -52,7 +52,7 @@ export const isLoggedIn = () => {
/* Returns true if authentication is enabled */ /* Returns true if authentication is enabled */
export const isAuthEnabled = () => { export const isAuthEnabled = () => {
const users = getUsers(); const users = getUsers();
return (users && users.length > 0); return (users.length > 0);
}; };
/* Returns true if guest access is enabled */ /* Returns true if guest access is enabled */
@ -151,7 +151,7 @@ export const isLoggedInAsGuest = () => {
*/ */
export const isUserAdmin = () => { export const isUserAdmin = () => {
const users = getUsers(); const users = getUsers();
if (!users || users.length === 0) return true; // Authentication not setup if (users.length === 0) return true; // Authentication not setup
if (!isLoggedIn()) return false; // Auth setup, but not signed in as a valid user if (!isLoggedIn()) return false; // Auth setup, but not signed in as a valid user
const currentUser = localStorage[localStorageKeys.USERNAME]; const currentUser = localStorage[localStorageKeys.USERNAME];
let isAdmin = false; let isAdmin = false;
@ -172,10 +172,8 @@ export const isUserAdmin = () => {
* then they will never be able to view the homepage, so no button needed * then they will never be able to view the homepage, so no button needed
*/ */
export const getUserState = () => { export const getUserState = () => {
const appConfig = getAppConfig();
const { notConfigured, loggedIn, guestAccess } = userStateEnum; // Numeric enum options const { notConfigured, loggedIn, guestAccess } = userStateEnum; // Numeric enum options
const users = appConfig.auth || []; // Get auth object if (!isAuthEnabled()) return notConfigured; // No auth enabled
if (!isAuthEnabled(users)) return notConfigured; // No auth enabled
if (isLoggedIn()) return loggedIn; // User is logged in if (isLoggedIn()) return loggedIn; // User is logged in
if (isGuestAccessEnabled()) return guestAccess; // Guest is viewing if (isGuestAccessEnabled()) return guestAccess; // Guest is viewing
return notConfigured; return notConfigured;

View File

@ -41,7 +41,7 @@ export default class ConfigAccumulator {
usersAppConfig.language = localStorage[localStorageKeys.LANGUAGE] usersAppConfig.language = localStorage[localStorageKeys.LANGUAGE]
|| appConfigFile.language || defaultLanguage; || appConfigFile.language || defaultLanguage;
// Don't let users modify users locally // Don't let users modify users locally
if (this.conf.auth) usersAppConfig.auth = appConfigFile.auth; if (appConfigFile.auth) usersAppConfig.auth = appConfigFile.auth;
// All done, return final appConfig object // All done, return final appConfig object
return usersAppConfig; return usersAppConfig;
} }