Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to extend a node object #43

Open
DmitryKamynin opened this issue Oct 26, 2021 · 0 comments
Open

How to extend a node object #43

DmitryKamynin opened this issue Oct 26, 2021 · 0 comments

Comments

@DmitryKamynin
Copy link

DmitryKamynin commented Oct 26, 2021

Hi, I made a library for router5 that uses your library. My library is responsible for private access to certain pages and I would like to extend it so that it can take on roles and restrict / grant access to certain application pages in accordance with them. My library also takes your nodes and recursively marks them private, but that's all I have. I would like to do something similar

import createRouter, {PluginFactory, Route} from "router5";
import accessPlugin, {AccessPluginRouter} from "./index";

const path: Route[] = [
  {
    name: 'root',
    path: '/',
    role: 'public', // transfer the role like this 
    public: true,  // or like this
  },
  {
    name: 'admin',
    path: '/admin',
    role: 'admin', // transfer the role like this
    children: [
      {
        name: 'adminPage',
        path: '/adminPage',
      },
    ]
  },
  {
    name: 'moderator',
    path: '/moderator',
    role: 'moderator', // transfer the role like this
    children: [
      {
        name: 'moderPage',
        path: '/moderatorPage',
      },
    ]
  }
];

const test = () => {
  const router = createRouter(path)
  router.usePlugin(accessPlugin({log: true}) as PluginFactory);
  (router as AccessPluginRouter).createPrivateAccess(path);
  (router as AccessPluginRouter).checkAccess('admin'); // or 'moderator'   // either true or 'public' for open access

  router.start();

  console.log('plugin test is successful')
}

test();

so that my plugin captures these roles and works with them. What would you advise me to do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant