This project is an authentication server built with JavaScript. It authenticates users by checking credentials against a SQLite database and issues JWT tokens to maintain user sessions. New users can also register through the server.
- User registration and authentication
- JWT-based session management
- SQLite database integration
Directory structure:
└── binadrish-authserverjs/
├── .env # Environment variables (e.g., JWT secret)
├── app.js # Main application entry point
├── package.json
└── src/
├── config/
│ └── dbConnector.js
├── controllers/
│ └── authController.js
├── models/
│ └── authModel.js
├── routes/
│ └── authRoutes.js
└── utils/
├── dateUtils.js
├── passwordUtils.js
├── uuidUtils.js
└── tests/
├── testDBConnection.js
└── testPasswordUtils.js
- Description: Registers a new user.
- Request Body:
{ "username": "desiredUsername", "password": "yourPassword" } - Response:
- 201 Created on success
- Error message if registration fails (e.g., user already exists)
- Description: Authenticates a user and returns a JWT token.
- Request Body:
{ "username": "yourUsername", "password": "yourPassword" } - Response:
- 200 OK with
{ "token": "<JWT token>" }on success - Error message if authentication fails
- 200 OK with
-
Install dependencies:
npm install
-
Configure environment:
Create a.envfile with your JWT secret and database path. -
Run the server:
node app.js
- Passwords are securely hashed in the database.
- JWT tokens should be kept safe on the client side.