This API provides user registration, login, logout, and token refresh functionality for the Pixelwand application.
Base URL: http://localhost:8000
- 1. User Registration
Endpoint: /register
Request Body:
Method: POST
Description: Allows users to create a new account by providing their email, password, and name.
{
"email": "user@example.com",
"password": "password123",
"confirm_password":"password123",
"username": "John Doe"
}
Response:
{
"token": "your-generated-jwt-token"
}
-
2. User Login
Endpoint: /login
Method: POST
Description: Allows registered users to log in by providing their email and password.
Request Body:
{
"email": "user@example.com",
"password": "password123"
}
Response:
{
"token": "your-generated-jwt-token"
}
-
3. User Logout
Endpoint: /logout
Method: GET
Description: Allows users to log out of a specific session, invalidating the provided session token.
Request Headers:
Authorization: Bearer your-jwt-tokenResponse:
{ "message": "Logout successful" }
-
4. Token Refresh
Endpoint: /refresh
Method: GET
Description: Allows users to refresh their session token, extending their session's validity.
Request Headers:
Authorization: Bearer your-jwt-tokenResponse:
{ "token": "your-newly-generated-jwt-token" }
-
5. Protected Route
Endpoint: /protected
Method: GET
Description: Allows only those authenticated users .
Request Headers:
Authorization: Bearer your-jwt-tokenResponse:
{ "message": "This is a protected route" }
To use protected endpoints (/logout, /refresh, /protected),
include the JWT token in the Authorization header as follows:
Bearer your-jwt-token.
For Unit and integration tests Use the npx jest command
ScreenShot Unit Testing
ScreenShot How To Add Bearer Token
To get started with the Pixelwand authentication system, follow these steps:
- I. Clone Git Repo
---- git clone https://github.com/Sahil-Sayyad/MongoDB_Authentication_System_Pixelwand.git - II. Install NPM dependencies
---- npm install - III. Set Up .env File
---- add monngoDb url -
- Use Postman or Thunder Client for Testing API Endpoints.
-
- Register a new user by making a POST request to /register with the required user information.
-
- Log in by making a POST request to /login with your email and password.
-
- Use the generated JWT token in the Authorization header for protected endpoints (/logout, /refresh, /protected).
-
- To log out, make a GET request to /logout with the JWT token in the Authorization header.
-
- To refresh your token, make a GET request to /refresh with the JWT token in the Authorization header.
-
- To see protected route, make a GET request to /protected with the JWT token in the Authorization header.
-
- For Unit Testing Use the Jest Type Follwoing Command npx jest