snowsenpai / auth-node-app

Authentication system with NodeJs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

node-auth-api

Simple nodejs authentication api
Data generated is stored as an array of objects in a json file. This isn't a secure approach, feel free to clone the project and integrate any database.

API Endpoints and HTTP Methods

API expects request body to have certain field(s) which will be used to validate, authorize and authenticate each request to the target endpoint.

POST: '/signup'

Creates a new user, will return an error message if validation fails
Request body:

{  
    "email":"",  
    "password":"",  
    "confirmPassword":"",  
    "firstName":"",  
    "lastName":"",  
    "address":""  
}  

POST: '/login'

Generates a token for existing user which is used to authenticate and authorize subsequent requests
Will return an error message if validation fails or user does not exist
Request body:

{  
    "email":"",  
    "password":""  
}  

GET: '/hello'

Returns the details of the user making the request, does not return user's password
Only accessible to an authenticated user with role USER
Request body:

{  
    "token":""  
}  

POST: '/update_user'

Updates the address field of the user making the request
Only accessible to an authenticated user with role USER
Request body:

{  
    "token":"",  
    "address":""  
}  

GET: '/all_users'

Returns all users that have signed up, without their passwords
Only accessible to an authenticated admin with role ADMIN
Request body:

{  
    "token":""
}  

To Run this project Clone it and install modules using

npm install  

Then Create .env file add JWT_SIGN and ADMIN_EMAIL Variable and specify Value.
Value specified to ADMIN_EMAIL will be used to add ADMIN role to a user
That's it. You are ready to go. To execute this project just type:

npm start  

Enjoy...!

About

Authentication system with NodeJs

License:MIT License


Languages

Language:JavaScript 100.0%