GithubHelp home page GithubHelp logo

francisco-vivas / lab-authentication-with-passport Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ironhack-labs/lab-authentication-with-passport

1.0 0.0 0.0 6.77 MB

JavaScript 75.63% Shell 0.26% Handlebars 24.11%

lab-authentication-with-passport's Introduction

logo_ironhack_blue 7

LAB | Authentication with PassportJS

Introduction

In previous lessons, we learned how important it is to manage your users (have them saved and retrieved) successfully. In this lab, you will do it one more time, just to make sure we are ready to move forward into new knowledge conquers. ๐Ÿ˜‰ Overall, the goal is to understand how authentication and authorization work in web applications, why these features are useful, and to be able to implement signup and login features using Passport.

Requirements

  • Fork this repo
  • Clone this repo

Submission

  • Upon completion, run the following commands:
git add .
git commit -m "done"
git push origin master
  • Create Pull Request so your TAs can check up your work.

Introductions

The provided code gives you the basic layout and organization for this assignment.

Iteration 0 | Initialize the project

After forking and cloning the project, you have to install all the dependencies:

$ cd lab-authentication-with-passport
$ npm install

Now you are ready to start. ๐Ÿš€

Iteration #1: The signup feature

The repo you cloned comes with a User model and a router file already made for you. It also has all the views you need, although some of them are empty. ๐Ÿ˜„

Add a new GET route to your routes/auth.routes.js file with the path /signup and point it to your views/auth/signup.hbs file. This route needs to render the signup form. Since you still haven't created the signup form, go ahead and add a form that makes a POST request to /signup, with a field for username and password.

Finally, add a POST route to your routes/auth.routes.js to receive the data from the signup form and create a new user with the data.

Make sure you install bcryptjs npm package and require it in routes/auth.routes.js file.

Iteration #2: The login feature

Follow the same logic as for the signup. Inside the routes/auth.routes.js file, create a GET route that will display the login form. Create a login form in the views/auth/login.hbs. The form should make a POST request to /login. Once you have the form, add another route to the router. This route needs to receive the data from the form and log the user in.

But wait...

To do that, we need to configure the session and initialize a session with passport in our app.js file. We also need to add the passport.serializeUser() and passport.deserializeUser() methods as well as define the Passport Local Strategy. The same as you were guided in the lesson, start with installing passport, passport-local and express-session. :bulb: Don't forget to add SECRET to the .env when creating a session.

Iteration #3: Private page

In the repo you forked, there is a file views/auth/private.hbs. This page is referenced in the routes/auth.routes.js with the path /private-page. We use the ensureLogin.ensureLoggedIn() method to make sure that the user is logged in before viewing this page.

If everything worked correctly, the user should be able to sign up, login, and then visit the page, where they will receive a personalized greeting.

Happy coding! โค๏ธ

lab-authentication-with-passport's People

Contributors

sandrabosk avatar lluisarevalo avatar mc100s avatar francisco-vivas avatar marcospalaciosiii avatar nickborbe avatar papuarza avatar

Stargazers

Roman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.