Skip to content

nickpersad/nodejs-mongodb-auth

Repository files navigation

nodejs-mongodb-auth


A Node.js app for basic authentication using MongoDB.

Running Locally

Prerequisites: Node.js. MongoDB.

git clone https://github.com/nickpersad/nodejs-mongodb-auth.git
cd nodejs-mongodb-auth
npm install
#Copy default environment file and add your config variables
cp .env.default .env
#Run in dev environment with hot reload or run with built app
npm run start:dev

Your app should now be running on localhost:8080.

API endpoints

All requests must be POST requests, GET requests are forbidden.

/api/signup

Only allows unique users, if a user exist, the user will be rejected. Passwords are hashed using [bcrypt] (https://en.wikipedia.org/wiki/Bcrypt). Sample request

{
	"username": "[email protected]",
	"password": "qwerty123456"
}

Sample response

{
  "success": true,
  "id": "5eb1a808b6228ew2b582ds19"
}
/api/signin

Sample request

{
	"username": "[email protected]",
	"password": "qwerty123456"
}

Sample response

{
  "success": true,
  "id": "5eb1a808b6228ew2b582ds19"
}
/api/user

Sample request

{}

Sample response

{
  "success": true,
  "results": [
    {
      "id": "22966r34df38a67003e55c11",
      "username": "[email protected]"
    },
    {
      "id": "5496921c990295718393a896",
      "username": "[email protected]"
    }
  ]
}
/api/signout

Sample request

{
    "username": "[email protected]"
}

Sample response

{
  "success": true
}

Environment file (.env)

########################################################################
##   Environment variables used for Node App
##
##   DEBUG - 1 is ON: errors/info will be shown in console. 0 is OFF: errors/info will be shown in GrayLog.
##   PORT - Port to set Node to listen on.
##   APPLICATION_NAME - Name of application.
##   MONGODB_CONNECTION - Connection to MongoDB.
##   EMAIL_HOST - Email hostname
##   EMAIL_PORT - Email port
##   EMAIL_USER - Email address/username
##   EMAIL_PASS - Email password
##
########################################################################

About

A Node.js app for basic authentication using MongoDB.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published