using with react (vite)
See original GitHub issueI 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
}
Issue Analytics
- State:
- Created a year ago
- Comments:16 (11 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Because I use the minimatch instead of the picomatch.
Ohk, I’ll look into it.