Coder Social home page Coder Social logo

angular2-jwt's Introduction

Angular 2 Authentication for Front End Masters Using JWT

Development server

Run ng serve for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.

Code scaffolding

Run ng generate component component-name to generate a new component. You can also use ng generate directive/pipe/service/class/module.

Build

Run ng build to build the project. The build artifacts will be stored in the dist/ directory. Use the -prod flag for a production build.

Running unit tests

Run ng test to execute the unit tests via Karma.

Running end-to-end tests

Run ng e2e to execute the end-to-end tests via Protractor. Before running the tests make sure you are serving the app via ng serve.

Further help

To get more help on the Angular CLI use ng help or go check out the Angular CLI README.


Implementing Authentication Challenges

  • Complete the onLoginSubmit and onSignupSubmit methods to make POST requests (sending the user's credentials) to the api/users/authenticate and api/users endpoints respectively
  • Provide a method in auth.service.js which saves the returned JWT in local storage
  • Create a logout method which removes the user's JWT from local storage
  • Provide buttons for Log In and Log Out in the home view and the toolbar

Step 1:

  • Create a screen for login and signup
  • Make a POST request with the user’s credentials
  • Store the JWT that comes back in local storage
  • Create a logout method which removes the token from local storage
  • Provide buttons for Log In and Log Out in the home view and the toolbar

Step 2:

  • Create an isAuthenticated method in the AuthService which checks whether the user's JWT has expired (Hint: use angular2-jwt for this)
  • Conditionally hide and show the Log In and Log Out links based on whether the user's JWT is expired

Step 3:

  • Use the payload from the JWT to generate a user profile
  • Display the user's gravatar, username, and email, along with the full JWT payload in the Profile view

Step 4:

  • Make an authenticated GET request to the /instructors endpoint and display the returned resources in the Instructors view
  • Add a method called isAdmin to auth.service.js and conditionally show and hide the Add Instructor button in the /instructor view based on whether the user is authenticated and is an admin +* Make an authenticated POST request to the /instructors endpoint to create a new instructor and return to the Instructors route to dispaly the newly created resource

Step 5:

  • Add data { requiresLogin: true } to the /profile, /instructor and /instructor/new routes +* Make an authenticated GET request to the /instructors endpoint and display the returned resources in the Instructors view
  • Add a method called isAdmin to auth.service.js and conditionally show and hide the Add Instructor button in the /instructor view based on whether the user is authenticated and is an admin

angular2-jwt's People

Watchers

 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.