RohanNero / block3d

An open-source authentication toolkit designed to streamline access control within Nextjs dapps.
https://block3d.gitbook.io/block3d
GNU General Public License v3.0
1 stars 0 forks source link

Add support for restriction per page instead of being global #11

Open RohanNero opened 5 days ago

RohanNero commented 5 days ago

Overview

Currently the block3dConfig allows you to determine if you want every rule criterion to be met, or at least one, before being allowed to view restricted pages. This is done through the strict field inside the config.

This is limiting per dapp since the rules are applied throughout the site with the exception of pages listed in the publicRoutes array.

Solution

Add a new field to each rule that marks what pages it should be applied to. Maybe we should also add an inverse rule that can only be used if the other new field isn't used, this way it works like a blacklist/whitelist.

For example, consider the new field terms enabled and disabled.

export const block3dConfig: Block3dConfig = {
  publicRoutes: [],
  strict: true, 
  rules: [
    {
      title: "Original Gangsters",
      type: "simple",
      enabled: ["/OGs"],
      addresses: ["0xd8da6bf26964af9d7eed9e03e53415d37aa96045", "0x4568D81dcfF2d12d035A250895454B3ec7e64428"],
    },
    {
      title: "USDC",
      type: "token", 
      strict: false,
      disabled: ["/OGs"],
      contracts: [
        {
          address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", 
          chainId: 1, 
          minimumBal: "100000000",
        },
        {
          address: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
          chainId: 42161,
          minimumBal: "1000000000",
        },
        {
          address: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
          chainId: 137,
          minimumBal: "1000000000",
        },
      ],
    },
  ],
};

In the example above, the /OGs page is restricted only by the Original Gangsters simple rule.