1.0.3 • Published 12 months ago

ankur_auth_rbac v1.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
12 months ago

Ankur Auth RBAC

Custom authentication and RBAC (Role-Based Access Control) for Node.js Express.

Installation

To install the package, run:

npm install ankur_auth_rbac

Usage

  1. Create a New File for Your Server:

    Create a new file in your project (e.g., server.js) and add the following code to set up and start the server using the ankur-custom-auth package:

    require("dotenv").config();
    const { createServer } = require("ankur_auth_rbac");
    
    const app = createServer();
    const PORT = process.env.PORT || 5000;
    
    app.listen(PORT, () => console.log(`Server running on port ${PORT}`));
  2. Configure Environment Variables:

    Ensure you have a .env file in your project root with the necessary configuration. Here’s an example .env file:

    PORT=5000
    MONGO_URI=your_mongodb_uri
    JWT_SECRET=yoursecret

    Replace your_mongodb_uri with your actual MongoDB connection URI.

API Endpoints

User Routes

  • Get All Users:

    • URL: /user/
    • Method: GET
    • Description: Retrieves a list of all users.
  • Get User Details by Username:

    • URL: /user/:username
    • Method: GET
    • Description: Retrieves details of a user based on the username.
  • Get User Details by ID:

    • URL: /user/id/:id
    • Method: GET
    • Description: Retrieves details of a user based on the user ID.
  • Search Users:

    • URL: /user/search
    • Method: GET
    • Description: Searches for users based on query parameters.
    • Example: /user/search?query=John to search for users with the name "John".
  • Update Username:

    • URL: /user/update-username/:id
    • Method: PUT
    • Description: Updates the username of a user based on the user ID.
  • Change User Password:

    • URL: /user/change-password/:id
    • Method: PUT
    • Description: Changes the password of a user based on the user ID.
  • Modify User Role:

    • URL: /user/modify-role/:id
    • Method: PUT
    • Description: Modifies the role of a user based on the user ID.
  • Delete User:

    • URL: /user/delete/:id
    • Method: DELETE
    • Description: Deletes a user based on the user ID.

Authentication Routes

  • Login:

    • URL: /auth/login
    • Method: POST
    • Description: Authenticates a user and returns a token.
  • Register:

    • URL: /auth/register
    • Method: POST
    • Description: Registers a new user.
  • Refresh Token:

    • URL: /auth/refresh
    • Method: POST
    • Description: Refreshes an authentication token.

Features

  • Custom Authentication: Provides endpoints for user authentication.
  • Role-Based Access Control (RBAC): Allows for fine-grained access control based on user roles.
  • CORS: Enables Cross-Origin Resource Sharing for your APIs.
  • MongoDB Integration: Connects to MongoDB for data storage.

Configuration

  • Environment Variables:
    • PORT: Port number for the server to listen on.
    • MONGODB_URI: MongoDB connection URI.
    • JWT_SECRET: JWT secret key.

Testing

You can test the server by creating a new project and running:

node server.js

Ensure that the environment variables are correctly set in the .env file.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

If you’d like to contribute to this project, please fork the repository and submit a pull request. For major changes, please open an issue first to discuss what you’d like to change.

Contact

For any questions or support, please reach out to Ankur Auti.

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago