question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

using with react (vite)

See original GitHub issue

I have problem when using node-casbin with react

import { newModel, Enforcer, newEnforcer } from 'casbin'
import { AuthActionVerb, AuthPossession, CustomAuthActionVerb } from 'constants/enum/auth'
import { ExecutionContext } from 'graphql/execution/execute'

import storage from './storage'

export type Permission = {
  resource: string
  action: AuthActionVerb | CustomAuthActionVerb
  possession?: AuthPossession
}

export const loadModel = () => {
  // rbac model
  const model = `
	[request_definition]
	r = sub, obj, act

	[policy_definition]
	p = sub, obj, act

	[role_definition]
	g = _, _

	[policy_effect]
	e = some(where (p.eft == allow))

	[matchers]
	m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act`

  const m = newModel()
  m.loadModelFromText(model)
  return m
}

export const loadPermissions = async (enforcer: Enforcer) => {
  const permissions = storage.getPermissions()
  await Promise.all([
    ...permissions.map((permission: any) => {
      return enforcer.addPolicy(permission[0], permission[1], permission[2])
    }),
  ])
}

export const initEnforcer = async (): Promise<Enforcer | null> => {
  const m = loadModel()

  const enforcer = await newEnforcer(m)

  await loadPermissions(enforcer)

  return enforcer
}

Screen Shot 2022-09-13 at 4 18 16 PM

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:16 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
nodececommented, Sep 17, 2022

Because I use the minimatch instead of the picomatch.

1reaction
Shivansh-yadav13commented, Sep 13, 2022

This looks like a dependency issue, @Shivansh-yadav13 Could you work on this?

Ohk, I’ll look into it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Set Up a React Project with Vite - DigitalOcean
Vite allows you to bootstrap a range of project types, not just React. Currently, it supports React, Preact, Vue, Lit, Svelte, and vanilla ......
Read more >
Creating a React.js App using Vite - Section.io
This tutorial will guide you on how to create a React application using Vite. It also highlights the benefits and features of Vite....
Read more >
Announcing Vite 2.0
Vite 2.0 ships with experimental SSR support. Vite provides APIs to efficiently load and update ESM-based source code in Node.js during development (almost...
Read more >
Vite 3.0 vs. Create React App: Comparison and migration guide
Vite was created by Evan You, the creator of Vue.js. However, it is platform-agnostic, meaning it can be used used to develop JavaScript/ ......
Read more >
Create a new React app with Vite - Scrimba.com
Vite makes life easy by prompting you with questions. First, Vite asks for your project name. Then, Vite will want to know if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found