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!

πŸ›‚ Remove page reload on auth failure (#981)

Alicia Sykesdb9d7e362dcd
diff --git a/services/get-user.js b/services/get-user.js
index b9c9e457..4d10ccdd 100644
--- a/services/get-user.js
+++ b/services/get-user.js
@@ -1,15 +1,15 @@
module.exports = (config, req) => {
try {
- if ( config.appConfig.auth.enableHeaderAuth ) {
- const userHeader = config.appConfig.auth.headerAuth.userHeader;
- const proxyWhitelist = config.appConfig.auth.headerAuth.proxyWhitelist;
- if ( proxyWhitelist.includes(req.socket.remoteAddress) ) {
- return { "success": true, "user": req.headers[userHeader.toLowerCase()] };
+ if (config.appConfig.auth.enableHeaderAuth) {
+ const { userHeader } = config.appConfig.auth.headerAuth;
+ const { proxyWhitelist } = config.appConfig.auth.headerAuth;
+ if (proxyWhitelist.includes(req.socket.remoteAddress)) {
+ return { success: true, user: req.headers[userHeader.toLowerCase()] };
}
}
return {};
} catch (e) {
- console.warn("Error get-user: ", e);
- return { 'success': false };
+ console.warn('Error get-user: ', e);
+ return { success: false };
}
-};
\ No newline at end of file
+};
diff --git a/src/main.js b/src/main.js
index 65f54a18..e112b4a8 100644
--- a/src/main.js
+++ b/src/main.js
@@ -23,6 +23,7 @@ import { toastedOptions, tooltipOptions, language as defaultLanguage } from '@/u
import { initKeycloakAuth, isKeycloakEnabled } from '@/utils/KeycloakAuth';
import { initHeaderAuth, isHeaderAuthEnabled } from '@/utils/HeaderAuth';
import Keys from '@/utils/StoreMutations';
+import ErrorHandler from '@/utils/ErrorHandler';
// Initialize global Vue components
Vue.use(VueI18n);
@@ -61,16 +62,19 @@ const mount = () => new Vue({
}).$mount('#app');
store.dispatch(Keys.INITIALIZE_CONFIG).then(() => {
- // Keycloak is enabled, redirect to KC login page
- if (isKeycloakEnabled()) {
+ if (isKeycloakEnabled()) { // If Keycloak is enabled, initialize auth
initKeycloakAuth()
.then(() => mount())
- .catch(() => window.location.reload());
- } else if (isHeaderAuthEnabled()) {
+ .catch((e) => {
+ ErrorHandler('Failed to authenticate with Keycloak', e);
+ });
+ } else if (isHeaderAuthEnabled()) { // If header auth is enabled, initialize auth
initHeaderAuth()
.then(() => mount())
- .catch(() => window.location.reload());
- } else { // If Keycloak not enabled, then proceed straight to the app
+ .catch((e) => {
+ ErrorHandler('Failed to authenticate with server', e);
+ });
+ } else { // If no third-party auth, just mount the app as normal
mount();
}
});
diff --git a/src/utils/HeaderAuth.js b/src/utils/HeaderAuth.js
index 33475de6..ff3369e2 100644
--- a/src/utils/HeaderAuth.js
+++ b/src/utils/HeaderAuth.js
@@ -3,7 +3,7 @@ import sha256 from 'crypto-js/sha256';
import ConfigAccumulator from '@/utils/ConfigAccumalator';
import { cookieKeys, localStorageKeys, serviceEndpoints } from '@/utils/defaults';
import { InfoHandler, ErrorHandler, InfoKeys } from '@/utils/ErrorHandler';
-import { logout } from '@/utils/Auth';
+import { logout as authLogout } from '@/utils/Auth';
const getAppConfig = () => {
const Accumulator = new ConfigAccumulator();
@@ -22,7 +22,6 @@ class HeaderAuth {
this.users = auth.users;
}
- /* eslint-disable class-methods-use-this */
login() {
return new Promise((resolve, reject) => {
const baseUrl = process.env.VUE_APP_DOMAIN || window.location.origin;
@@ -44,6 +43,7 @@ class HeaderAuth {
}
});
} catch (e) {
+ ErrorHandler('Error while trying to login using header authentication', e);
reject(e);
}
}
@@ -51,8 +51,9 @@ class HeaderAuth {
});
}
+ // eslint-disable-next-line class-methods-use-this
logout() {
- logout();
+ authLogout();
}
}