FlexGuardDB is a Node.js-based RESTful API offering powerful user authentication and database management capabilities. It allows users to create custom tables, manage their data through CRUD operations, and securely handle authentication using JWT tokens.
-
User Authentication:
- Register, Login, Logout, and Refresh Tokens with JWT.
- Access tokens (15 minutes) for short-term sessions.
- Refresh tokens (7 days) for long-term access continuity.
- Secure password hashing using bcrypt.
-
Database Operations:
- Dynamically create tables with custom schemas, including primary keys and auto-increment fields.
- Perform Insert, Update, and Select operations with complex conditions.
- Supports AND/OR operators and various comparison operators (
==
,>
,<
, etc.).
-
Token Management:
- Tokens are stored in compressed JSON files to ensure persistence across restarts.
- Both access tokens and refresh tokens are invalidated during logout.
-
Supported Data Types:
- INTEGER, STRING, BOOLEAN, and DATE.
-
Register and Login:
- A user registers and logs in to receive access and refresh tokens.
-
Create a Table:
- The user creates a new table dynamically, defining columns with primary keys and auto-increment if needed.
-
Insert Data:
- The user inserts rows into the table with values matching the schema.
-
Query Data:
- Users query data with complex conditions using logical operators (
AND
,OR
).
- Users query data with complex conditions using logical operators (
-
Token Refresh:
- When the access token expires, the refresh token is used to get a new access and refresh token.
-
Logout:
- Logging out invalidates both access and refresh tokens, preventing unauthorized access.
Register a new user.
{
"email": "user@example.com",
"username": "user123",
"password": "Password@123"
}
- 201 Created: User registered successfully.
- 400 Bad Request: Missing or invalid fields.
- 409 Conflict: Username or email already exists.
Log in and receive access and refresh tokens.
{
"username": "user123",
"password": "Password@123"
}
- 200 OK: Login successful, with tokens returned.
- 401 Unauthorized: Invalid credentials.
Log out and invalidate tokens.
{
"accessToken": "access-token",
"refreshToken": "refresh-token"
}
- 200 OK: Logged out successfully.
- 400 Bad Request: Invalid tokens.
- 401 Unauthorized: Invalid or expired access token.
Refresh tokens by issuing new access and refresh tokens.
{
"token": "refresh-token"
}
- 200 OK: Tokens refreshed, with new access and refresh tokens returned.
- 401 Unauthorized: Invalid or expired refresh token.
Create a new table with a custom schema.
{
"tableName": "users",
"columns": [
{ "name": "id", "type": "INTEGER", "primaryKey": true, "autoIncrement": true },
{ "name": "name", "type": "STRING" },
{ "name": "age", "type": "INTEGER" }
]
}
- 201 Created: Table created successfully.
- 400 Bad Request: Invalid table schema.
- 409 Conflict: Table already exists.
Insert a row into a table.
{
"tableName": "users",
"values": [null, "Alice", 25]
}
- 201 Created: Data inserted successfully.
- 400 Bad Request: Invalid data or table does not exist.
- 409 Conflict: Duplicate primary key value.
Query data with optional conditions and logical operators.
{
"tableName": "users",
"conditions": [
[{ "column": "age", "operator": ">", "value": 20 }, "AND", { "column": "name", "operator": "!=", "value": "Bob" }]
]
}
- 200 OK: Array of matching rows.
- 400 Bad Request: Invalid query or table does not exist.
Update rows matching specific conditions.
{
"tableName": "users",
"conditions": [{ "column": "id", "operator": "==", "value": 1 }],
"updates": { "age": 30 }
}
- 200 OK: Number of rows updated.
- 400 Bad Request: Invalid update data or table does not exist.
- ==: Equals
- !=: Not Equals
- >: Greater Than
- >=: Greater Than or Equal
- <: Less Than
- <=: Less Than or Equal
- INTEGER: Whole numbers.
- STRING: Text values.
- BOOLEAN: True/false values.
- DATE: Date objects.
-
Clone the Repository:
git clone <repository-url> cd <repository-name>
-
Install Dependencies:
npm install
-
Start the Server:
node index.js
-
Access the API Documentation: Open your browser and navigate to:
http://localhost:3000
- Tokens and user data are saved in compressed JSON files to ensure persistence across server restarts.
- Access tokens are valid for 15 minutes, while refresh tokens are valid for 7 days.
This project is licensed under the MIT License.