Git Product home page Git Product logo

user-authentication-api's Introduction

HapiJS Authentication Sample

This sample project demonstrates how to set up a user authentication API with Hapi.js using JSON Web Tokens. There are several endpoints exposed in the sample, including user login and signup, along with an example of a protected instructors resource.

Demo API

The API for the course is served at https://user-authentication-api.now.sh/api

Installation and Running the App

Clone the repo, then:

npm install
node server.js

The app will be served at localhost:3001.

Local Setup

To setup the API locally, you will need to run MongoDB or have an MLab instance. Create a .env file and populate it with the following values:

SECRET_KEY=<secret_key>
MLAB_USER=<mlab_user>
MLAB_PASSWORD=<secret_key>
MLAB_DOMAIN=<domain>
MLAB_DB=<database>

Available Routes

POST /api/users

  • Used for signing up a user. Accepts username, email, and password to create a user. Returns a JWT.

POST /api/users/authenticate

  • Used for logging a user in. Accepts username or email and password to authenticate a user. Returns a JWT.

GET /api/users

  • Returns all users in the database. Requires a valid JWT with an admin scope.

PATCH /api/user/{id}

  • Updates a user. Requires a valid JWT with an admin scope.

GET /api/instructors

  • Returns all instructors in the database. Requires a valid JWT.

GET /api/instructors/{id}

  • Returns a specific instructor in the database. Requires a valid JWT.

POST /api/instructors

  • Saves a new instructor in the database. Requires a valid JWT with an admin scope.

DELETE /api/instructors/{id}

  • Deletes an instructor with a specific id. Requires a valid JWT with an admin scope.

POST /api/users/check

  • Checks whether a user already exists or not. Useful for doing async form validation.

user-authentication-api's People

Contributors

chenkie avatar

Watchers

James Cloos 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.