This is a lightweight authentication API built using Node.js and Express. It supports user sign-up, sign-in, and profile retrieval with an in-memory storage approach.
- Sign Up: Register new users.
- Sign In: Authenticate existing users and receive a JWT token.
- Profile Management: Fetch user information using a valid token.
- In-Memory Storage: No database required; all data is stored in-memory for simplicity.
- Live Application: https://tridibs-in-memory-authentication.netlify.app
- Frontend Repository: GitHub Repo
-
Clone the repository:
git clone https://github.com/Tridib11/Authentication-api.git
-
Navigate to the project folder:
cd Authentication-api
-
Install dependencies:
npm install
-
Start the server:
node index.js
The server will run on
http://localhost:3000
.
- Description: Check if the server is running.
- Response:
{ "msg": "Server is running" }
- Description: Register a new user.
- Request Body:
{ "username": "your_username", "password": "your_password" }
- Response:
{ "msg": "You are signed in successfully" }
- Error:
{ "msg": "User already exists" }
- Description: Log in a user and receive a JWT token.
- Request Body:
{ "username": "your_username", "password": "your_password" }
- Response:
{ "token": "your_jwt_token" }
- Error:
{ "msg": "Sorry user does not exist!" }
- Description: Fetch user information. Requires a valid JWT token.
- Headers:
{ "token": "your_jwt_token" }
- Response:
{ "username": "your_username", "password": "your_password" }
- Error:
{ "msg": "User not found" }
auth
: Verifies the JWT token.logger
: Logs the incoming request method.
- Backend: Node.js, Express
- Authentication: JWT (JSON Web Tokens)
- CORS: Enabled for cross-origin requests
- Frontend: Deployed on Netlify
- Sign Up to create a new account.
- Sign In to receive a JWT token.
- Use the token to access the Profile Information endpoint.
.
├── index.js # Main server file
├── package.json # Project dependencies
└── README.md # Documentation
This project is licensed under the MIT License. Feel free to use and modify it as needed.
Tridib
GitHub