This module is responsible for handling user authentication, including signing up, signing in, and verifying user identities. It also provides administrative routes for managing users.
Description: Registers a new user.
Request Body:
{
"email": "[email protected]",
"password": "securepassword"
}
Response:
- Success:
{ "message": "user created successfully", "isSuccess": true, "token": "<jwt-token>" }
- Error:
{ "err": "<error-message>", "isSuccess": false }
Description: Logs in an existing user.
Request Body:
{
"email": "[email protected]",
"password": "securepassword"
}
Response:
- Success:
{ "message": "Login successful.", "token": "<jwt-token>", "isSuccess": true }
- Error:
{ "message": "Invalid credentials.", "isSuccess": false }
Description: Verifies a user using a token.
Headers:
Authorization
:Bearer <jwt-token>
Response:
- Success:
{ "message": "User verified successfully", "isSuccess": true }
- Error:
{ "message": "Invalid or expired token.", "isSuccess": false }
Description: Fetches a list of all registered users. Requires admin authentication.
Headers:
Authorization
:Bearer <admin-jwt-token>
Response:
- Success:
{ "users": [ { "id": "<user-id>", "email": "[email protected]" } ], "isSuccess": true }
- Error:
{ "message": "Access denied.", "isSuccess": false }
Purpose: Hashes the user's password before storing it in the database.
Purpose: Verifies the JWT token provided in the request headers.
Purpose: Ensures the requester is an authenticated admin.
- Inserts a new user record into the database.
- Generates a JWT token upon successful registration.
- Validates user credentials.
- Generates a JWT token upon successful authentication.
- Decodes and validates the provided JWT token.
- Confirms user identity.
- Fetches a list of users from the database (admin-only route).
- Node.js
- MySQL or compatible database
FLEXIBASE_AUTH_SECRET_KEY
: Secret key for signing JWT tokens.DB_HOST
,DB_EXPOSE_PORT
,DB_NAME
: Database connection details.
- Clone the repository:
git clone https://github.com/ModularMinds/flexibase-auth.git
- Install dependencies:
npm install
- Set up environment variables in a
.env
file. - Start the server:
npm start
Use tools like Postman or curl to interact with the API endpoints.
Contributions are welcome! Please create a pull request with your changes.
This project is licensed under the MIT License.