Giter Club home page Giter Club logo

authentication-system's Introduction

Authentication-System-Api

A Basic Authentication system built in Node.js

Installation & Setup

  1. Install Node.js and MongoDB.
  2. Clone this repository and install its dependencies
$ git clone https://github.com/tariqiqbal27/authentication-system
$ cd authentication-system
$ npm install
  1. Edit the config.js file and enter database name
module.exports = {
        MongoURL: 'mongodb://127.0.0.1:27017/your-database-name
}
  1. From within the authentication-system directory start the server
$ npm run dev
  1. Access the Server Api from localhost:3000

Usage

  • For CREATING AN ACCOUNT

Request

POST /register

Body - JSON

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

Response - JSON

{
    "code": "ACCOUNT_CREATED",
    "msg": "User Created"
}
  • For LOGIN

Request

POST /login

Body - JSON

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

Response - JSON

{
    "id": "5d9908678d1d0e1144c87b2c"
}
  • For GETTING AUTHENTICATED USER DATA

Request

GET /user

Response - JSON

{
    "_id": "5d9908678d1d0e1144c54c2c",
    "email": "[email protected]",
    "createdAt": "2019-10-05T21:17:27.379Z",
    "updatedAt": "2019-10-05T21:17:27.379Z"
}
  • For GETTING USER ID

Request

GET /user/userid

Response - String

5d9908678d1d0e1144c54c2c
  • For LOGOUT

Request

POST /user/logout

Response - JSON

{
    "code": "AUTH_LOGOUT_SUCCESS",
    "msg": "Logout Successfully"
}
  • For CHANGING USER PASSWORD

Request

PATCH /user/change_password

Body - JSON

{
	"old_password":"password1",
	"new_password":"password2"
}

Response - JSON

{
    "code": "AUTH_PASSWORD_CHANGE",
    "msg": "Password changes Successfully"
}
  • For DELETING USER

Request

DELETE /user/delete

Response

{
    "code": "DELETED_OK",
    "msg": "Account Deleted"
}

Exception Handling

Session Exception

  • If User is not Authenticated

Response

{
    "code": "AUTH_NOT_SUCCESS",
    "msg": "User not Authenticated"
}
  • If User is Authenticated

Response

{
    "code": "AUTH_OK",
    "msg": "User already authenticated"
}

Register Exception

  • if Password length is less than 8

Response

{
    "code": "AUTH_MIN_PASSWORD",
    "msg": "Password length must be greater than 7"
}
  • if Email Already registered

Response

{
    "code": "EMAIL_ALREADY_EXIST",
    "msg": "Email Already Exist"
}
  • if Email & Password Field are blank

Response

{
    "code": "AUTH_BLANK_FIELD",
    "msg": "Enter Email/Password"
}

Login Exception

  • If Email Or Password are wrong

Response

{
    "code": "LOGIN_INVALID",
    "msg": "Email & password wrong"
}

Change Password

  • if Old password is wrong

Response

{
    "code": "AUTH_PASSWORD_INCORRECT",
    "msg": "Incorrect Account Password"
}
  • if New password and Old password are same

Response

{
    "code": "AUTH_PASSWORD_SAME",
    "msg": "New Password cannot be old password"
}

authentication-system's People

Contributors

tariqiqbal27 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.