F
F
floydback2018-06-25 19:46:22
JSON Web Token
floydback, 2018-06-25 19:46:22

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
}

and after dancing with tambourines, it is not clear from where this library makes requests to the root of the site.
Honestly, they are thinking of returning to cookie authorization. Can someone tell me a normal library, or an article-instruction for authorization in the PSA application
ps my stack: Rails (api-mode), Devise + VueJS (axios, routing, vuex)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2018-06-25
@floydback

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},
});

components/auth.js
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 question

Ask a Question

731 491 924 answers to any question