fixed user logout bug
This commit is contained in:
@ -41,6 +41,9 @@ export default {
|
||||
console.log('SetCsrftoken', token)
|
||||
state.csrf_token = token
|
||||
},
|
||||
SetLogouttoken (state, token) {
|
||||
state.logout_token = token
|
||||
},
|
||||
setToken (state, data) {
|
||||
console.log('setToken', data)
|
||||
state.uid = data.current_user.uid
|
||||
@ -183,10 +186,10 @@ export default {
|
||||
},
|
||||
userLogin ({ dispatch, commit, state }, credentials) {
|
||||
return new Promise((resolve, reject) => {
|
||||
dispatch('getToken', credentials)
|
||||
dispatch('postUserLogin', credentials)
|
||||
// TODO: catch failed login
|
||||
.then((response) => {
|
||||
console.log('userLogin dispatch getToken response', response)
|
||||
console.log('userLogin dispatch postUserLogin response', response)
|
||||
|
||||
if (response.status === 200) {
|
||||
commit('setToken', response.data)
|
||||
@ -194,7 +197,7 @@ export default {
|
||||
console.log('User Loggedin', state.isAdmin, state.isAdherent)
|
||||
// have to reload systematicly because of autologout library not loaded if not logged in the begining
|
||||
if (state.isAdmin) {
|
||||
window.location.reload()
|
||||
// window.location.reload()
|
||||
}
|
||||
if (state.isAdherent) {
|
||||
// router.push({
|
||||
@ -202,7 +205,7 @@ export default {
|
||||
// })
|
||||
// // TODO: openCloseHamMenu(false)
|
||||
// dispatch('Common/openCloseHamMenu', false)
|
||||
window.location = '/base'
|
||||
// window.location = '/base'
|
||||
}
|
||||
// else {
|
||||
// // * window.location.reload()
|
||||
@ -211,18 +214,18 @@ export default {
|
||||
})
|
||||
} else {
|
||||
commit('setLoginMessage', response.data.message)
|
||||
console.warn('Issue with getToken', response)
|
||||
console.warn('Issue with postUserLogin', response)
|
||||
console.log('user loggein failed')
|
||||
Promise.reject(new Error('user loggein failed'))
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.warn('Issue with Dispatch getToken', error)
|
||||
console.warn('Issue with Dispatch postUserLogin', error)
|
||||
Promise.reject(error)
|
||||
})
|
||||
})
|
||||
},
|
||||
getToken ({ dispatch, commit, state }, credentials) {
|
||||
postUserLogin ({ dispatch, commit, state }, credentials) {
|
||||
return REST.post('/user/login?_format=json',
|
||||
credentials,
|
||||
{
|
||||
@ -237,24 +240,34 @@ export default {
|
||||
console.log('csrftoken', data)
|
||||
commit('SetCsrftoken', data)
|
||||
console.log('state.csrf_token', state.csrf_token)
|
||||
const params = {
|
||||
token: state.csrf_token
|
||||
}
|
||||
REST.get(`/user/${state.uid}?_format=json`, params)
|
||||
// INFO this endpoiunt needs https://www.drupal.org/project/logout_token
|
||||
REST.get('/session/logout/token')
|
||||
.then(({ data }) => {
|
||||
console.log('user REST getUser data', data)
|
||||
console.log('roles', data.roles)
|
||||
// with session_limit, only here we are certain that the user is logged
|
||||
commit('setUser', data)
|
||||
if (data.roles) {
|
||||
commit('setRoles', data.roles)
|
||||
console.log('logout_token', data)
|
||||
commit('SetLogouttoken', data)
|
||||
const params = {
|
||||
token: state.csrf_token
|
||||
}
|
||||
// console.log('customer_profiles', data.customer_profiles.length)
|
||||
// if (data.customer_profiles.length) {
|
||||
// dispatch('getUserProfiles', data.customer_profiles[data.customer_profiles.length - 1].target_id)
|
||||
// }
|
||||
dispatch('getUserFlagColls')
|
||||
resolve()
|
||||
REST.get(`/user/${state.uid}?_format=json`, params)
|
||||
.then(({ data }) => {
|
||||
console.log('user REST getUser data', data)
|
||||
console.log('roles', data.roles)
|
||||
// with session_limit, only here we are certain that the user is logged
|
||||
commit('setUser', data)
|
||||
if (data.roles) {
|
||||
commit('setRoles', data.roles)
|
||||
}
|
||||
// console.log('customer_profiles', data.customer_profiles.length)
|
||||
// if (data.customer_profiles.length) {
|
||||
// dispatch('getUserProfiles', data.customer_profiles[data.customer_profiles.length - 1].target_id)
|
||||
// }
|
||||
dispatch('getUserFlagColls')
|
||||
resolve()
|
||||
})
|
||||
.catch(error => {
|
||||
console.warn('Issue with getUser', error)
|
||||
Promise.reject(error)
|
||||
})
|
||||
})
|
||||
.catch(error => {
|
||||
console.warn('Issue with getUser', error)
|
||||
@ -424,14 +437,20 @@ export default {
|
||||
commit('closeFlagColl')
|
||||
},
|
||||
userLogout ({ commit, state }) {
|
||||
const credentials = qs.stringify({
|
||||
token: state.csrf_token
|
||||
const params = qs.stringify({
|
||||
// format: 'json'
|
||||
// token: state.logout_token
|
||||
})
|
||||
REST.post('/user/logout', credentials)
|
||||
const config = {
|
||||
headers: {
|
||||
'X-CSRF-Token': state.csrf_token
|
||||
}
|
||||
}
|
||||
REST.post('/user/logout?format=json&token=' + state.logout_token, params, config)
|
||||
.then(resp => {
|
||||
console.log('userLogout resp', resp)
|
||||
commit('setLoggedOut')
|
||||
// window.location.reload(true) ???
|
||||
// commit('setLoggedOut')
|
||||
// window.location.reload(true)
|
||||
})
|
||||
.catch(error => {
|
||||
console.warn('Issue with logout', error)
|
||||
|
Reference in New Issue
Block a user