Implement auto-redirect on LogIn view when auth is disabled
authorAdam Dullage <redacted>
Wed, 8 May 2024 07:12:21 +0000 (08:12 +0100)
committerAdam Dullage <redacted>
Wed, 8 May 2024 07:12:21 +0000 (08:12 +0100)
client/views/LogIn.vue

index 339c1529e039a45a6e9301ef128dd38620ac2469..9c0edbea49514f8b13122cca55d55fed73a53ad5 100644 (file)
 
 <script setup>
 import { mdilLogin } from "@mdi/light-js";
-import { ref } from "vue";
-import { useRouter, useRoute } from "vue-router";
 import { useToast } from "primevue/usetoast";
+import { ref, watch } from "vue";
+import { useRouter } from "vue-router";
 
-import { getToken, apiErrorHandler } from "../api.js";
+import { apiErrorHandler, getToken } from "../api.js";
 import CustomButton from "../components/CustomButton.vue";
 import Logo from "../components/Logo.vue";
 import TextInput from "../components/TextInput.vue";
 import { authTypes } from "../constants.js";
 import { useGlobalStore } from "../globalStore.js";
-import { storeToken } from "../tokenStorage.js";
 import { getToastOptions } from "../helpers.js";
+import { storeToken } from "../tokenStorage.js";
 
 const props = defineProps({ redirect: String });
 
@@ -93,4 +93,16 @@ function logIn() {
       }
     });
 }
+
+// Redirect to home if authentication is disabled.
+// Implemented as a watch to allow for delayed config load.
+watch(
+  () => globalStore.authType,
+  () => {
+    if (globalStore.authType === authTypes.none) {
+      router.push({ name: "home" });
+    }
+  },
+  { immediate: true },
+);
 </script>
git clone https://git.99rst.org/PROJECT