inertia-permissions 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/dist/usePermissions.d.ts +7 -0
- package/dist/usePermissions.js +12 -0
- package/package.json +23 -0
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# inertia-permissions
|
|
2
|
+
|
|
3
|
+
Permission helpers for Inertia.js + Spatie Laravel Permission.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
npm install inertia-permissions
|
|
8
|
+
|
|
9
|
+
## Use
|
|
10
|
+
import { usePermissions } from "inertia-permissions";
|
|
11
|
+
|
|
12
|
+
const { can, canAny } = usePermissions();
|
|
13
|
+
|
|
14
|
+
{can("roles.store") && <Button />}
|
|
15
|
+
{canAny(["roles.update", "roles.destroy"]) && <Actions />}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { usePage } from "@inertiajs/react";
|
|
2
|
+
export function usePermissions() {
|
|
3
|
+
var _a, _b;
|
|
4
|
+
const { auth } = usePage().props;
|
|
5
|
+
const permissions = (_a = auth === null || auth === void 0 ? void 0 : auth.permissions) !== null && _a !== void 0 ? _a : [];
|
|
6
|
+
const roles = (_b = auth === null || auth === void 0 ? void 0 : auth.roles) !== null && _b !== void 0 ? _b : [];
|
|
7
|
+
const isSuperAdmin = roles.includes("super-admin");
|
|
8
|
+
const can = (permission) => isSuperAdmin || permissions.includes(permission);
|
|
9
|
+
const canAny = (perms) => isSuperAdmin || perms.some((p) => permissions.includes(p));
|
|
10
|
+
const canAll = (perms) => isSuperAdmin || perms.every((p) => permissions.includes(p));
|
|
11
|
+
return { can, canAny, canAll, roles, permissions };
|
|
12
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "inertia-permissions",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Permission helpers for Inertia.js + Spatie",
|
|
5
|
+
"main": "dist/usePermissions.js",
|
|
6
|
+
"types": "dist/usePermissions.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [],
|
|
14
|
+
"author": "abusayedkhan.com",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@inertiajs/react": "^2.3.13",
|
|
18
|
+
"react": "^19.2.4"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"typescript": "^5.9.3"
|
|
22
|
+
}
|
|
23
|
+
}
|