npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ankur_auth_rbac

v1.0.3

Published

Custom authentication and RBAC for Node.js Express

Downloads

16

Readme

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.