Skip to content

I built an API with authentication using JSON Web Tokens and bcryptjs. I wrote a variety of middleware while completing API functionality.

Notifications You must be signed in to change notification settings

sim-taa/authentication

 
 

Repository files navigation

Authentication and Testing Sprint Challenge

Read these instructions carefully. Understand exactly what is expected before starting this Sprint Challenge.

This challenge allows you to practice the concepts and techniques learned over the past sprint and apply them in a concrete project. This sprint explored Authentication and Testing. During this sprint, you studied authentication, JSON web tokens, unit testing, and backend testing. In your challenge this week, you will demonstrate your mastery of these skills by creating a dad jokes app.

This is an individual assessment. All work must be your own. All projects will be submitted to Codegrade for automated review. You will also be given feedback by code reviewers on Monday following the challenge submission. For more information on the review process click here.

You are not allowed to collaborate during the sprint challenge.

Project Setup

  • [√] Run npm install to install your dependencies.
  • [√] Build your database executing npm run migrate.
  • [√] Run tests locally executing npm test.

Project Instructions

Users must be able to call the [POST] /api/auth/register endpoint to create a new account (NOTE: REQUIRE bcryptjs in the router), and the [POST] /api/auth/login endpoint to get a token (NOTE: REQUIRE jsonwebtoken - in the router(?)).

Note: no middleware needed to complete jokes router(?)

We also need to make sure nobody without the token can call [GET] /api/jokes and gain access to our dad jokes. NOTE: WRITE A MIDDLEWARE TO DO THIS. See MVP(2)

We will hash the user's password using bcryptjs, and use JSON Web Tokens and the jsonwebtoken library.

MVP

Your finished project must include all of the following requirements (further instructions are found inside each file):

  • An authentication workflow with functionality for account creation and login, implemented inside api/auth/auth-router.js.
  • Middleware used to restrict access to resources from non-authenticated requests, implemented inside api/middleware/restricted.js.
  • A minimum of 2 tests per API endpoint, written inside api/server.test.js.

IMPORTANT Notes:

  • Do not exceed 2^8 rounds of hashing with bcryptjs.
  • If you use environment variables make sure to provide fallbacks in the code (e.g. process.env.SECRET || "shh").
  • You are welcome to create additional files but do not move or rename existing files or folders.
  • Do not alter your package.json file except to install extra libraries. Do not update existing packages.
  • The database already has the users table, but if you run into issues, the migration is available.

Submission format

  • Check Codegrade before the deadline to compare its results against your local tests.

Interview Questions

Be prepared to demonstrate your understanding of this week's concepts by answering questions on the following topics.

  1. Differences between using sessions or JSON Web Tokens for authentication.
  2. What does bcryptjs do to help us store passwords in a secure manner?
  3. How are unit tests different from integration and end-to-end testing?
  4. How does Test Driven Development change the way we write applications and tests?

About

I built an API with authentication using JSON Web Tokens and bcryptjs. I wrote a variety of middleware while completing API functionality.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%