Passing logged-in user credentials from twig to vue.

This commit is contained in:
krzysiej
2022-06-21 12:39:22 +02:00
parent 00bb86f798
commit c054f791b1
6 changed files with 38 additions and 11 deletions

View File

@@ -52,6 +52,7 @@ export default {
},
computed: {
...mapState('booksmodule', ['books']),
...mapState('usermodule', ['user']),
},
methods: {
...mapActions('booksmodule', [
@@ -62,7 +63,7 @@ export default {
this.findAll(this.searchTerm);
},
updateHistory: function () {
if (history.pushState) {
if (this.searchTerm && history.pushState) {
let url = window.location.protocol + "//" + window.location.host + window.location.pathname + '?search=' + this.searchTerm;
window.history.pushState({path: url}, '', url);
}

View File

@@ -4,6 +4,7 @@ import {
LOGIN_SUCCESS,
LOGIN_ERROR,
STORE_USER_INFO,
LOGIN_STOP,
} from '../mutation-types.js'
export default {
@@ -11,7 +12,7 @@ export default {
state: {
isLoading: false,
error: null,
user: null,
user: window.user,
userUri: null,
},
getters: {
@@ -36,6 +37,9 @@ export default {
state.error = null;
state.userUri = userUri;
},
[LOGIN_STOP](state, userUri) {
state.isLoading = false;
},
[STORE_USER_INFO](state, user) {
state.isLoading = false;
state.error = null;
@@ -60,8 +64,6 @@ export default {
dispatch('getUserInfo', response.headers.location)
commit(LOGIN_SUCCESS, response.headers.location);
//this.$emit('user-authenticated', userUri);
//this.email = '';
//this.password = '';
}).catch(error => {
if (error.response.data.error) {
@@ -70,7 +72,7 @@ export default {
}
}).finally(() => {
// this.isLoading = false;
commit(LOGIN_STOP);
})
},
async getUserInfo({commit}, userUri) {

View File

@@ -13,5 +13,6 @@ export const
LOGIN_START = "LOGIN_START",
LOGIN_SUCCESS = "LOGIN_SUCCESS",
LOGIN_ERROR = "LOGIN_ERROR",
LOGIN_STOP = "LOGIN_STOP",
STORE_USER_INFO = "STORE_USER_INFO"
;