diff --git a/assets/vue/App.vue b/assets/vue/App.vue index 6a5144e4cf..a764ae23c8 100644 --- a/assets/vue/App.vue +++ b/assets/vue/App.vue @@ -50,6 +50,7 @@ import {isEmpty} from "lodash"; import ConfirmDialog from "primevue/confirmdialog"; import Toast from 'primevue/toast'; import { useToast } from 'primevue/usetoast'; +import { useSecurityStore } from "./store/securityStore" const apolloClient = new ApolloClient({ link: createHttpLink({ @@ -128,10 +129,12 @@ if (!isEmpty(window.user)) { } const store = useStore(); +const securityStore = useSecurityStore() const payload = {isAuthenticated, user}; store.dispatch('security/onRefresh', payload); +securityStore.user = window.user onMounted(() => { const app = document.getElementById('app'); diff --git a/assets/vue/components/Login.vue b/assets/vue/components/Login.vue index 861ef2d4cd..6e5e916b33 100644 --- a/assets/vue/components/Login.vue +++ b/assets/vue/components/Login.vue @@ -79,11 +79,13 @@ import InputText from 'primevue/inputtext'; import Password from 'primevue/password'; import InputSwitch from 'primevue/inputswitch'; import {useI18n} from "vue-i18n"; +import { useSecurityStore } from "../store/securityStore" const route = useRoute(); const router = useRouter(); const store = useStore(); const {t} = useI18n(); +const securityStore = useSecurityStore() const login = ref(''); const password = ref(''); @@ -108,6 +110,8 @@ async function performLogin() { await store.dispatch("security/login", payload); if (!store.getters["security/hasError"]) { + securityStore.user = store.state["security/user"] + if (typeof redirect !== "undefined") { await router.push({path: redirect.toString()}); } else { diff --git a/assets/vue/store/securityStore.js b/assets/vue/store/securityStore.js new file mode 100644 index 0000000000..3472c389cf --- /dev/null +++ b/assets/vue/store/securityStore.js @@ -0,0 +1,12 @@ +import { defineStore } from "pinia" +import { isEmpty } from "lodash" + +export const useSecurityStore = defineStore("security", { + state: () => ({ + user: null, + }), + + getters: { + isAuthenticated: (state) => !isEmpty(state.user), + }, +})