Skip to content

Instantly share code, notes, and snippets.

@sergeysova
Created September 27, 2019 13:10
Show Gist options
  • Select an option

  • Save sergeysova/2e367b6315b2059571cde1782125dd42 to your computer and use it in GitHub Desktop.

Select an option

Save sergeysova/2e367b6315b2059571cde1782125dd42 to your computer and use it in GitHub Desktop.
const routes = [
{
name: "auth.login",
path: "/login",
component: LoginPage,
guards: [checkAuthn({ auth: false, redirectTo: "home" })],
},
{
name: "transactions.list",
path: "/transactions",
component: TransactionsPage,
guargs: [
checkAuthn({ auth: true, redirectTo: "auth.login", method: "replace" }),
checkRoles(["admin", "user"]),
],
children: [
{
name: 'transactions.foo',
path: '/foo',
component: DemoPage,
// guards from parents applies
},
]
},
];
@sergeysova
Copy link
Copy Markdown
Author

const checkRoles = (roles) =>
  (route, { auth }) =>
    roles.includes(auth.role)
      ? route
      : undefined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment