authera 1.2.8-test-6 → 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.
@@ -6,10 +6,9 @@ export function useAuth() {
6
6
  if (!ctx)
7
7
  throw new Error("useAuth must be used within an AuthContext");
8
8
  // -------------------------------------------------- data
9
- const { permits: permitsData = [], ...user } = (ctx.userData ||
10
- {});
9
+ const { permits: permitsData, ...user } = ctx.userData;
10
+ const authera_props = ctx.authera_props;
11
11
  const prm = (permitsData || []);
12
- console.trace();
13
12
  // -------------------------------------------------- funtions
14
13
  const isPermitted = (perm) => {
15
14
  return prm.includes(perm);
@@ -69,6 +68,6 @@ export function useAuth() {
69
68
  setAccessToken,
70
69
  setRefreshToken,
71
70
  logout,
72
- ...ctx.authera_props,
71
+ ...authera_props,
73
72
  };
74
73
  }
@@ -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): import("react/jsx-runtime").JSX.Element | null | undefined;
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 } = useAuth();
6
- const isPermitted = isPermittedHook(permits);
7
- if (action === "redirect" && !isPermitted) {
8
- window.location.href = fallback_401_url;
9
- return null;
10
- }
11
- if (action === "show") {
12
- if (isPermitted)
13
- return _jsx(_Fragment, { children: children });
14
- else
15
- return null;
16
- }
17
- if (action === "hide") {
18
- if (isPermitted)
19
- return null;
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "authera",
3
- "version": "1.2.8-test-6",
3
+ "version": "1.2.8-test-8",
4
4
  "description": "this project is a simple auth hook for react",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",