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 expects request body to have certain field(s) which will be used to validate, authorize and authenticate each request to the target endpoint.
Creates a new user, will return an error message if validation fails
Request body:
{
"email":"",
"password":"",
"confirmPassword":"",
"firstName":"",
"lastName":"",
"address":""
}
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":""
}
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":""
}
Updates the address
field of the user making the request
Only accessible to an authenticated user with role USER
Request body:
{
"token":"",
"address":""
}
Returns all users that have signed up, without their passwords
Only accessible to an authenticated admin with role ADMIN
Request body:
{
"token":""
}
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...!