From 2b9b289496448af5b7280c184ace1768b2c70736 Mon Sep 17 00:00:00 2001 From: Ryan Pratt Date: Thu, 19 Dec 2024 14:16:14 -0700 Subject: [PATCH] Redirect from /login if user is already authenticated --- .../src/tools/base/AppNav.vue | 4 ++++ .../src/tools/base/Login.vue | 22 ++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/base/AppNav.vue b/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/base/AppNav.vue index 3672bd43e..242c57a7f 100644 --- a/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/base/AppNav.vue +++ b/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/base/AppNav.vue @@ -343,6 +343,10 @@ export default { window.location.pathname == '/tools' || window.location.pathname == '/tools/' ) { + // TODO: There's some sort of race condition here which makes this flaky if the user went to '/login' with + // no `?redirect=` query param while they were already authenticated. That sends them to '/', causing + // another redirect here that gets stepped on, so they're left at '/'. The nav bar shows, so they can click + // on a tool, or refresh the page to make this redirect actually happen. for (let key of Object.keys(this.shownTools)) { if (this.appNav[key].shown) { history.replaceState(null, '', this.appNav[key].url) diff --git a/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/base/Login.vue b/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/base/Login.vue index 77ba3390b..2518468c7 100644 --- a/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/base/Login.vue +++ b/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/base/Login.vue @@ -64,7 +64,7 @@ { - this.alert = 'Incorrect password' + if (error?.status === 401) { + this.alert = 'Incorrect password' + } else { + this.alert = error.message || 'Something went wrong...' + } this.alertType = 'warning' - this.showAlert = true + this.showAlert = !noAlert }) }, setPassword: function () {