Answer the question
In order to leave comments, you need to log in
Nuxt + Express. How to do authentication?
Good morning! I'm a noob at this, need help.
On Php, everything was easy, when registering, I wrote a hash to the database for the user and threw the same hash into cookies. When a user came to the site, the hash was compared and if it matched, the user was automatically logged into the site. Plus, it was easy to check the access level (user or admin), after additional. checks simply added an access level to the session. On the right pages - checked the access level.
All this was done in a few lines of code.
Now I started to develop spa using Nuxt + Express.
I barely figured out Sequelize (and then, at the initial level, but for now it’s enough for further steps. I haven’t used the orm before).
It turns out I need to do something similar. In ready-made solutions, of which I shoveled a sufficient number in a few days, a lot of DIFFERENT applied things are used - passport, different strategies for it, express-session, bodyparser - I remember those that are most common, so I got completely confused.
Save xD
Answer the question
In order to leave comments, you need to log in
https://medium.com/devschacht/node-hero-chapter-8-...
passport is just a wrapper that defines a single interface for authorizations that are chosen as "strategies". If an interface is specified, you can make strategies for it in the form of packages, which are taken from npm. For simple authorization from the database, local is enough, only you need to write the request yourself, as in the manual at the link above.
express-session - a package that adds cookies to the client, reads it and puts the corresponding entry from the database in req.session
body-parser - parses the content of the http message and if there is json or say form data, then it makes an object out of it and puts it in req. body. Doesn't work with multipart, it needs other packages.
Don’t be fooled by JWT, there are few advantages from it, you need to understand where it is useful, and where it is not very. Although of course you need to know how it works.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question