Answer the question
In order to leave comments, you need to log in
What pre-built VueJS authorization library is out there?
I found only https://github.com/websanova/vue-auth but I can't call it a ready solution. There is no normal documentation, in order to figure it out, I had to climb into their code, invent something like
const token = localStorage.getItem('user-token')
if (token) {
axios.defaults.headers.common['Authorization'] = 'Bearer ' + token
}
Answer the question
In order to leave comments, you need to log in
Everything is configured normally, the documentation is shit simple.
Vue.use(VueAuth, {
auth: require('./components/auth'),
http: require('@websanova/vue-auth/drivers/http/axios.1.x.js'),
router: require('@websanova/vue-auth/drivers/router/vue-router.2.x.js'),
rolesVar: 'role',
loginData: {url: '/api-token-auth/', method: 'POST', redirect: '/somepage', fetchUser: true},
fetchData: {url: '/users/me/', method: 'GET', enabled: true},
refreshData: {url: '/users/me/', method: 'GET', enabled: true, interval: 5},
parseUserData: function(res) { return res; },
logoutData: {url: 'auth/logout', method: 'POST', redirect: '/login', makeRequest: false},
});
module.exports = {
request: function (req, token) {
this.options.http._setHeaders.call(this, req, { Authorization: 'Token ' + token });
},
response: function (res) {
let token = res.data.token
if (token) {
return token;
}
}
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question