Internal: Add security store based on Pinia - refs BT#20915

pull/4838/head
Angel Fernando Quiroz Campos 1 year ago
parent 2793a5da3a
commit 4ac5a27bab
  1. 3
      assets/vue/App.vue
  2. 4
      assets/vue/components/Login.vue
  3. 12
      assets/vue/store/securityStore.js

@ -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');

@ -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 {

@ -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),
},
})
Loading…
Cancel
Save