0👍
So, I got my answer on the Vue forum just a few seconds after posting this : I need to return
the promise of my authenticate
method. So the new code is :
export function authenticate (context, creds) {
let requestConfig = {
headers: {
'Content-Type': 'application/json'
}
}
return Vue.http.post(
url + apiPaths.auth,
creds,
requestConfig
).then(response => {
return response.json()
}).then(data => {
context.commit('setUsername', creds.username)
context.commit('setJwtToken', data.token)
}).catch(error => {
console.log('error:')
console.log(error)
})
}
- [Vuejs]-Why i see cordova android emulator error?
- [Vuejs]-Unit testing vue component, using vue-cli, can't test parent methods?
0👍
This looks a bit fishy for me.
First: I hope, you are not using vuex
to hold your crentials/token.
Security tip #1, Security tip #2.
I would recommend only setting authenticated:true
and use that for your requests.
Then:
Have a look at global guards of the vue router
, which could be leveraged, to check, whether the current user is logged in.
Last:
To programatically route to sections of your app, you could use router.push.
So, you have to store, which route the user wanted before the login page and programmatically push
this route afterwards.
- [Vuejs]-Vuetify v-select input element does not hold any value
- [Vuejs]-Vue components data and methods disappear on one item when rendered with v-for as Vuetify's cards
Source:stackexchange.com