This project is basically a simple authentication system API using node js, Express js, and Mongodb incorporating Json Web Token for user authentication. The system will have two types of users -
- Admin
- Normal user
Admin can register themselves, while normal users cannot register directly. Instead, they can only be added by an authenticated admin.
Note
- To test this application you need postman.
- Also this project is deployed on render so you don't need to fork and clone. To check this project, you can follow this following steps.
Ser. no | Tools |
---|---|
1 | Node js |
2 | Express js |
3 | Mongodb |
4 | Json Web Token |
5 | Bcrypt |
6 | validator |
https://admin-panel-bi8j.onrender.com/api/admin/register
Method : POST
1. Username (string), 2. Email (string), 3. Password (string)
Important
- Username and Email should be unique else throw error.
- Username must be at least 6 and at most 12 characters.
- Enter proper email as it's validated else throw error.
{
"Email":"abcd@gmail.com",
"Password":"Abcd@123",
"Username":"Abcd12"
}
{
"message": "Admin registered successfully",
"success": true
}
{
"message": "all fields are required",
"success": false
}
{
"message": "Email already exists",
"success": false
}
{
"message": "Username already exists",
"success": false
}
{
"message": "Admin already exists",
"success": false
}
https://admin-panel-bi8j.onrender.com/api/admin/login
Method : POST
1. Username (string), 3. Password (string)
Important
- Username should be unique .
- Username must be at least 6 and at most 12 characters.
- After successful login you will receive a token as a response and this token will be needed while adding the normal users because using this token server will check if the admin is valid or not
{
"Username":"Abcd12"
"Password":"Abcd@123",
}
{
"message": "admin login successful",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY1NGY3YzEzMGVjNGIzZDEyOTlkNDA4OCIsImlhdCI6MTY5OTcwODE1MH0.MDI_COak7Nt2nmztBsD79HqJFpSK-qTAwCgv0YxRp-E",
"success": true
}
{
"message": "all fields are required",
"success": false
}
{
"message": "Admin doesn't exists",
"success": false
}
{
"message": "Invalid credential",
"success": false
}
https://admin-panel-bi8j.onrender.com/api/admin/add-user
Method : POST
1. Username (string), 2. Email (string), 3. Password (string) 4. Authorization: Bearer [token] (which is generated at the time of admin's login)
Important
- Username and Email should be unique else throw error.
- Username must be at least 6 and at most 12 characters.
- Enter proper email as it's validated else throw error.
- Also make sure that a admin can't register himself/herself as a normal user.
{
"Email":"user@gmail.com",
"Username":"user112",
"Password":"User@123"
}
{
"message": "user added successfully",
"success": true
}
{
"message": "unauthorized admin",
"success": false
}
{
"message": "all fields are required",
"success": false
}
{
"message": "Email already exists",
"success": false
}
{
"message": "Username already exists",
"success": false
}
{
"message": "User already exists",
"success": false
}
https://admin-panel-bi8j.onrender.com/api/admin/all-users
Method : GET
1. Authorization: Bearer [token] (which is generated at the time of admin's login)
{
"allUsers": [
{
"_id": "6551a5e471e908af038a656c",
"Username": "Abcd11",
"Email": "abcd11@gmail.com",
"Password": "$2b$10$JQScAMm3/Xw5JT2/5TYixecym8ZNhXMsc5NItgkZhRER8UMzMLCqy",
"__v": 0
},
{
"_id": "6551a61371e908af038a6572",
"Username": "Abcd111",
"Email": "abcd111@gmail.com",
"Password": "$2b$10$icB3V1f8apH.gvLZc1nscumiacop6WBFbmKyOHutqJa8FuvoTN7BO",
"__v": 0
},
{
"_id": "6551aaf826c7856aa4cf9bdf",
"Username": "Abc1saaaaaaa",
"Email": "abcd34@gmail.com",
"Password": "$2b$10$dDiXk3Hm71qrkKGun91jf.8H0ykqB7l2gzhmePbUI3GWgGjgsTPX.",
"__v": 0
},
],
"success": true
}
{
"message": "unauthorized admin",
"success": false
}
{
"message": "users not found",
"success": false
}