Answer the question
In order to leave comments, you need to log in
Creating authentication on Vue+Express?
I can’t figure out what and where to use to create authentication / authorization, when there is a separate API on Express, and a client on Vue.
You need Passport.js, but what strategy should you use? Passport-local or passport-jwt? If jwt, then where to transfer the token? Is it possible without jwt? How to check it? Do I need Vuex, or can I do without it to create a simple authentication? I shoveled a bunch of lessons, but there is little intelligible. I created a simple registration, hashing passwords and that's it. On authorization I stop for the third time, after which I postpone this question. Although this is the most interesting thing in development)
The main plug now with passport.js is in the login route.
app.post('/profile', passport.authenticate('jwt', { session: false }),
function(req, res) {
res.send(req.user.profile);
}
);
Answer the question
In order to leave comments, you need to log in
Here is an option on how to implement authorization on the Vue side - https://medium.com/@pavelgonzales/best-practices-%...
The same can be easily found on Express. And be guided by your needs.
I recently dealt with the issue myself. Specifically, in your piece of code, you must transfer your JWT token from the client, the passport decrypts it, and if it matches the desired user, then you have been authorized. At the same time, as far as I understand, it is impossible to fake this token without knowing the secret key, just steal it.
Detailed lessons that helped me - Here
From about 42-43 lessons
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question