Code Monkey home page Code Monkey logo

node-auth's Introduction

Build Status bitHound Code bitHound Overall Score Coverage Status Known Vulnerabilities PRs Welcome NSP Status

NODE Auth

It is a project to help you to create an api using nodejs, with this kit, you will avoid starting from the very beginning using authentication and MongoDB as a database.

How to use

To use it, you will need to have a mongodb server and change it's config on config.js into src folder.

If you'll run it into a Docker using the project's docker-compose file, you don't need to take care with it (mongo server).

config.js

module.exports = {
	database: 'mongodb://localhost:27017/node-auth'
};

OR For docker users:

module.exports = {
	database: 'mongodb://database/node-auth'
};

Running api

1 - git clone https://github.com/abdalla/node-auth.git
2 - npm install
3 - npm start

To use into Docker

1 - git clone https://github.com/abdalla/node-auth.git
2 - npm install
3 - docker-compose up

Running tests

To run the tests you don't need to have mongodb installed.

Running tests to make sure everything is working good.

It is pretty simple...

npm test

or to get coverage statistics

npm run test-cover

Routes

Setup

Used to create the first user (admin)

Verbose: POST

http://localhost:3000/api/setup

Response:

{
  "success": true,
  "user": { user information }
}

Authentication

Used to authenticate the user and get the token used to comunicate with the other routes.

Verbose: POST

http://localhost:3000/api/auth

Header:

Content-Type: application/json

Body:

{
	"email": "[email protected]",
	"password": "admin"
}

Response:

{
	"success": true,
	"message": "enjoy",
	"token": "<token>"
}

Get all users

Used to get all users.

Verbose: GET

http://localhost:3000/api/users

Header:

x-access-token: "<token>"

Response:

{
	"success": true,
	"users": []
}

Get user by id

Used to get a specific user.

Verbose: GET

http://localhost:3000/api/user/{userId}

Header:

x-access-token: "<token>"

Response:

{
  "success": true,
  "user": { user information }
}

Create new user

Used to create a new user.

Verbose: POST

http://localhost:3000/api/user

Header:

Content-Type: application/json
x-access-token: "<token>"

Body:

{
	"user": {
		"name": "user full name",
		"userName": "user name",
		"password": "password",
		"email": "[email protected]",
		"admin": false
	}
}

Response:

{
  "success": true,
  "user": { user information }
}

Update an user

Used to update an user information (except password).

Verbose: PUT

http://localhost:3000/api/user

Header:

Content-Type: application/json
x-access-token: "<token>"

Body:

{
	"user": {
		"_id": REQUIRED,
		"name": "user full name (optional)",
		"userName": "user name  (optional)",
		"email": "[email protected]  (optional)",
		"admin": false(optional)
	}
}

Response:

{
  "success": true,
  "user": { user information }
}

Update user password

Used to change the user password.

Verbose: PUT

http://localhost:3000/api/userpassword/{userId}

Header:

Content-Type: application/json
x-access-token: "<token>"

Body:

{
	"currentPassword": "currentPassword",
	"newPassword": "newPassword"
}

Response:

{
  "success": true,
  "user": { user information
  }
}

Delete an user

Used to delete an user.

Verbose: DELETE

http://localhost:3000/api/user/<userId>

Header:

x-access-token: "<token>"

Response:

{
  "success": true,
  "user": { user information }
}

Core libraries

For App

Express - The most popular Node framework ( thinking to change to koa )

Mongoose - Interact with our MongoDB database

Morgan - Log requests to the console so we can see what is happening

body-parser - Get parameters from our POST requests

jsonwebtoken - Create and Verify our JSON Web Tokens

bluebird - Promise

For Test

Mocha - The testing framework

Chai - Gives you some useful tools for testing, such as expect/should functions.

mongodb-memory-server - Allows you to run Mongoose in-memory instead of connecting to a persistent database.

Factory-girl - For creating factories for your models.

Faker - For creating randomized data

Supertest - For performing requests in your tests

Istanbul - JS code coverage tool

FUTURE

This project will be migrate to Typescript soon!

node-auth's People

Contributors

abdalla avatar dependabot[bot] avatar snyk-bot avatar tadeuqc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

node-auth's Issues

Docker

Implement docker to run the app and database.

2FA

Implement 2FA option

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.