authera 1.2.8-test-7 → 1.2.8-test-8
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/hooks/useAuth.js +4 -3
- package/dist/web/guard.d.ts +1 -1
- package/dist/web/guard.js +15 -20
- package/package.json +1 -1
package/dist/hooks/useAuth.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { AuthContext, } from "../helper/context";
|
|
2
|
-
import React
|
|
2
|
+
import React from "react";
|
|
3
3
|
export function useAuth() {
|
|
4
4
|
// -------------------------------------------------- context
|
|
5
5
|
const ctx = React.useContext(AuthContext);
|
|
6
6
|
if (!ctx)
|
|
7
7
|
throw new Error("useAuth must be used within an AuthContext");
|
|
8
8
|
// -------------------------------------------------- data
|
|
9
|
-
const { permits: permitsData
|
|
9
|
+
const { permits: permitsData, ...user } = ctx.userData;
|
|
10
|
+
const authera_props = ctx.authera_props;
|
|
10
11
|
const prm = (permitsData || []);
|
|
11
12
|
// -------------------------------------------------- funtions
|
|
12
13
|
const isPermitted = (perm) => {
|
|
@@ -67,6 +68,6 @@ export function useAuth() {
|
|
|
67
68
|
setAccessToken,
|
|
68
69
|
setRefreshToken,
|
|
69
70
|
logout,
|
|
70
|
-
...
|
|
71
|
+
...authera_props,
|
|
71
72
|
};
|
|
72
73
|
}
|
package/dist/web/guard.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ export interface AuthGuardProps {
|
|
|
4
4
|
permits: string[];
|
|
5
5
|
action: "show" | "hide" | "redirect";
|
|
6
6
|
}
|
|
7
|
-
export default function AuthGuard({ children, permits, action, }: AuthGuardProps):
|
|
7
|
+
export default function AuthGuard({ children, permits, action, }: AuthGuardProps): void;
|
package/dist/web/guard.js
CHANGED
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useAuth } from "../hooks/useAuth";
|
|
4
2
|
export default function AuthGuard({ children, permits, action, }) {
|
|
5
|
-
const { isPermittedAll: isPermittedHook, fallback_401_url } =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
else
|
|
21
|
-
return _jsx(_Fragment, { children: children });
|
|
22
|
-
}
|
|
3
|
+
// const { isPermittedAll: isPermittedHook, fallback_401_url } =
|
|
4
|
+
// useAuth<string>();
|
|
5
|
+
// const isPermitted = isPermittedHook(permits);
|
|
6
|
+
// if (action === "redirect" && !isPermitted) {
|
|
7
|
+
// window.location.href = fallback_401_url;
|
|
8
|
+
// return null;
|
|
9
|
+
// }
|
|
10
|
+
// if (action === "show") {
|
|
11
|
+
// if (isPermitted) return <>{children}</>;
|
|
12
|
+
// else return null;
|
|
13
|
+
// }
|
|
14
|
+
// if (action === "hide") {
|
|
15
|
+
// if (isPermitted) return null;
|
|
16
|
+
// else return <>{children}</>;
|
|
17
|
+
// }
|
|
23
18
|
}
|