Intro to User Authentication

This week I worked on the user authentication section of the bootcamp tutorials. I learned about passport.js which helps us make user authentication much easier. I also learn about to new npm packages called passport-local and passport-local-mongoose. The last thing I learn about was sessions which allows us to keep a user login until the user themselves sign out.

I created a simple form without styling it that allows a user login, register, and logout . I wrote code which allowed someone to sign in and be able to see a secret page which you can only see if you are login in. I did this by creating middleware. Middleware is some function that runs when the request is made and the response is received. When I tried to reach “/secrets” without logging in it would send me back to the index page. This was because of the middleware in the /secrets request which checks if the requested route was made by an authenticated user. If someone would try to login then there was another middleware which checked if the user existed. If they do exist then it sent them to the secrets page but if they didn’t they would just be redirected to the index page. This was really cool stuff to learn and I hope to learn a lot more about user authentication later on.


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *