Closed cwgitadmin closed 1 year ago
@nodece @Zxilly @Shivansh-yadav13
API Code
exports.getUserPermissions = async function (req, res) {
try {
const subject = req.query.subject;
var e = await enforcer();
var permissions = await casbin.casbinJsGetPermissionForUser(e, subject);
res.send({data:permissions});
} catch (error) {
console.log("getPermissionsByRoleId:", error);
res.status(400).json(error.message);
}
};
Frontend Code
const authorizer = new Authorizer(
"auto", // mode
{
endpoint: `http://localhost:3001/roles/user-permissions`,
requestHeaders: {
method: ["GET"],
}
}
);
// Set your visitor.
// Casbin.js will automatically sync the permission with your backend Casbin service.
authorizer.setUser("74");
// Evaluate the permission
const result = await authorizer.can("read", "/dashboard/*");
console.log("result", result);
Please help me to fix this error.
@cwgitadmin hi, why close?
I got solution for above mentioned issue
I got solution for above mentioned issue
pls provide the solution here
I am facing same issue
Why closed? @vasanth123 did you fix this issue? Please share your solution here :)
I have solved this problem. The problem was in order of request.
When you calling method can
of authorizer
class, it alwas enforces your request in own order:
enforcer.enforce(this.user, domain, object, action)
And if you have own request order, authorizer.can
will throws error.
So I created own library that solves this problem, you can write your request in order which you want. https://github.com/Dias1c/casbin-js/tree/main
@Dias1c can you make PR to merge this to this repo?