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.
@@ -1,12 +1,13 @@
1
1
  import { AuthContext, } from "../helper/context";
2
- import React, { useMemo } from "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 = [], ...user } = useMemo(() => ctx.userData || {}, []);
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
- ...ctx.authera_props,
71
+ ...authera_props,
71
72
  };
72
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-7",
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",