Coder Social home page Coder Social logo

node-auth3-project's Introduction

Authentication using JSON Web Tokens (JWTs)

Topics

  • Authentication.
  • Express Middleware.
  • JSON Web Tokens (JWTs).
  • Hashing Passwords.

Description

In this project we'll implement a full authentication workflow (register/login/logout/restrict endpoint) using Node.js, Express, SQLite and JSON Web Tokens on the server.

Download Project Files

  • Fork and Clone this repository.
  • CD into the folder where you cloned the repository.
  • Do your magic!

Assignment

Use Node.js, Express and Knex to build an API that provides Authentication functionality using SQLite to store User information.

The user schema should include: username, password and department. The department should be a string used to group the users. No need for a departments table or setting up relationships.

Use JSON Web Tokens to keep users authenticated across requests.

Design and build the following endpoints.

Method Endpoint Description
POST /api/register Creates a user using the information sent inside the body of the request. Hash the password before saving the user to the database.
POST /api/login Use the credentials sent inside the body to authenticate the user. On successful login, create a new JWT with the user id as the subject and send it back to the client. If login fails, respond with the correct status code and the message: 'You shall not pass!'
GET /api/users If the user is logged in, respond with an array of all the users contained in the database. If the user is not logged in respond with the correct status code and the message: 'You shall not pass!'.

Stretch Problem

  • add the code necessary so that when a client makes a GET request to /api/users the server only returns documents with the same department as the logged in user. For example if the logged in user belongs to the finance department, then only users with the finance department should be returned; if the logged in user is in sales only users on the sales department should be returned.
  • implement a React client:
    • use create-react-app to generate a application to server as the client for the Web API.
    • inside the React application add client-side routes and components for signup, signin and showing the list of users stored in the database.
    • the /signup route should provide a form to gather username, password and department for the user and make a POST request to the /api/register route on the API. If the user is created successfully, take the returned token, save it to the browser's local storage and redirect the user to the /users route, where they should see the list of users.
    • the /signin route should provide a form to gather username and password for the user and make a POST request to the /api/login route on the API. Upon successful login, persist the returned token to the browser's local storage and redirect the user to the /users route.
    • the /users route should read the token from local storage and make a GET request to the /api/users route on the API attaching the token as the value of the Authorization header.
    • provide a button to sign out that will remove the token from local storage.
  • add any extra functionality to make the application more user friendly like showing a message and redirecting to /signin if an unauthenticated user tries to access the list of users in the /users route.

node-auth3-project's People

Contributors

karthikv avatar luishrd avatar mixelpixel avatar seanchen1991 avatar taithethai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

node-auth3-project's Issues

Endpoint Instructions

Endpoint instructions for /api/login are the same as for auth-i, instructing us to use sessions instead of JWT

server dependencies should be client dependencies

In a separate terminal window, CD into the client folder.
type yarn install to download the client dependencies.
type yarn start to execute the client application.
Ensure that you have an instance of MongoDB running.

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.