@geomak/ui 6.21.1 → 6.23.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/dist/index.cjs +36 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +49 -7
- package/dist/index.d.ts +49 -7
- package/dist/index.js +36 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5884,42 +5884,59 @@ function SecureLayout({
|
|
|
5884
5884
|
permissions,
|
|
5885
5885
|
requiredPermissions,
|
|
5886
5886
|
requireAllPermissions,
|
|
5887
|
+
route,
|
|
5887
5888
|
canAccess,
|
|
5888
5889
|
loadingFallback,
|
|
5889
5890
|
fallback,
|
|
5891
|
+
onGranted,
|
|
5890
5892
|
onDeny,
|
|
5891
5893
|
className = ""
|
|
5892
5894
|
}) {
|
|
5893
5895
|
const reduced = framerMotion.useReducedMotion();
|
|
5894
|
-
const [state, setState] = React26.useState("checking");
|
|
5895
5896
|
const rolesKey = JSON.stringify(roles);
|
|
5896
5897
|
const requiredRolesKey = JSON.stringify(requiredRoles);
|
|
5897
5898
|
const permissionsKey = JSON.stringify(permissions);
|
|
5898
5899
|
const requiredPermissionsKey = JSON.stringify(requiredPermissions);
|
|
5900
|
+
const passesSync = () => {
|
|
5901
|
+
let authed = isAuthenticated;
|
|
5902
|
+
if (authed === void 0 && token !== void 0) authed = tokenValid(token);
|
|
5903
|
+
if (authed === void 0) authed = true;
|
|
5904
|
+
if (!authed) return false;
|
|
5905
|
+
if (requiredRoles?.length && !has(roles, requiredRoles, requireAllRoles)) return false;
|
|
5906
|
+
if (requiredPermissions?.length && !has(permissions, requiredPermissions, requireAllPermissions)) return false;
|
|
5907
|
+
return true;
|
|
5908
|
+
};
|
|
5909
|
+
const [state, setState] = React26.useState(
|
|
5910
|
+
() => !passesSync() ? "denied" : canAccess ? "checking" : "granted"
|
|
5911
|
+
);
|
|
5899
5912
|
React26.useEffect(() => {
|
|
5900
5913
|
let cancelled = false;
|
|
5901
|
-
|
|
5902
|
-
const evaluate = async () => {
|
|
5903
|
-
let authed = isAuthenticated;
|
|
5904
|
-
if (authed === void 0 && token !== void 0) authed = tokenValid(token);
|
|
5905
|
-
if (authed === void 0) authed = true;
|
|
5906
|
-
if (!authed) return false;
|
|
5907
|
-
if (requiredRoles?.length && !has(roles, requiredRoles, requireAllRoles)) return false;
|
|
5908
|
-
if (requiredPermissions?.length && !has(permissions, requiredPermissions, requireAllPermissions)) return false;
|
|
5909
|
-
if (canAccess && !await canAccess()) return false;
|
|
5910
|
-
return true;
|
|
5911
|
-
};
|
|
5912
|
-
evaluate().then((ok) => {
|
|
5914
|
+
const finish = (ok) => {
|
|
5913
5915
|
if (cancelled) return;
|
|
5914
5916
|
setState(ok ? "granted" : "denied");
|
|
5915
|
-
if (
|
|
5916
|
-
|
|
5917
|
+
if (ok) onGranted?.();
|
|
5918
|
+
else onDeny?.();
|
|
5919
|
+
};
|
|
5920
|
+
if (!passesSync()) {
|
|
5921
|
+
finish(false);
|
|
5922
|
+
} else if (!canAccess) {
|
|
5923
|
+
finish(true);
|
|
5924
|
+
} else {
|
|
5925
|
+
const result = canAccess(route);
|
|
5926
|
+
if (result && typeof result.then === "function") {
|
|
5927
|
+
setState("checking");
|
|
5928
|
+
result.then((ok) => finish(Boolean(ok)));
|
|
5929
|
+
} else {
|
|
5930
|
+
finish(Boolean(result));
|
|
5931
|
+
}
|
|
5932
|
+
}
|
|
5917
5933
|
return () => {
|
|
5918
5934
|
cancelled = true;
|
|
5919
5935
|
};
|
|
5920
5936
|
}, [
|
|
5921
5937
|
isAuthenticated,
|
|
5922
5938
|
token,
|
|
5939
|
+
route,
|
|
5923
5940
|
requireAllRoles,
|
|
5924
5941
|
requireAllPermissions,
|
|
5925
5942
|
canAccess,
|
|
@@ -5929,10 +5946,12 @@ function SecureLayout({
|
|
|
5929
5946
|
requiredPermissionsKey
|
|
5930
5947
|
]);
|
|
5931
5948
|
if (state === "checking") {
|
|
5932
|
-
|
|
5949
|
+
if (loadingFallback === null) return null;
|
|
5950
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: ["flex min-h-[8rem] items-center justify-center", className].filter(Boolean).join(" "), children: loadingFallback !== void 0 ? loadingFallback : /* @__PURE__ */ jsxRuntime.jsx(Spinner2, {}) });
|
|
5933
5951
|
}
|
|
5934
5952
|
if (state === "denied") {
|
|
5935
|
-
|
|
5953
|
+
if (fallback === null) return null;
|
|
5954
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: className || void 0, children: fallback !== void 0 ? fallback : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-h-[8rem] flex-col items-center justify-center gap-1 rounded-xl border border-border bg-surface p-8 text-center", children: [
|
|
5936
5955
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm font-semibold text-foreground", children: "Access denied" }),
|
|
5937
5956
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-foreground-muted", children: "You don\u2019t have permission to view this content." })
|
|
5938
5957
|
] }) });
|