authera 1.2.8 → 2.0.2

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,5 +1,5 @@
1
1
  import React from "react";
2
- import { type AuthHookSettings } from "..";
2
+ import { type AuthHookSettings } from "./types";
3
3
  export type userBaseData<T extends string> = {
4
4
  id: string;
5
5
  username: string;
@@ -0,0 +1,10 @@
1
+ import { customeFunc, storagesNames } from "./storage";
2
+ export interface AuthHookSettings<T extends string> {
3
+ backendUrl: string;
4
+ storage: storagesNames | customeFunc;
5
+ tokenType: "jwt";
6
+ refreshStrategy: "silent";
7
+ fallback_401_url: string;
8
+ on_after_login?: (response_data: any) => void;
9
+ on_after_step?: (step_key: string) => void;
10
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { AuthContext, } from "../helper/context";
2
3
  import React from "react";
3
4
  export function useAuth() {
@@ -7,6 +8,7 @@ export function useAuth() {
7
8
  throw new Error("useAuth must be used within an AuthContext");
8
9
  // -------------------------------------------------- data
9
10
  const { permits: permitsData, ...user } = ctx.userData;
11
+ const authera_props = ctx.authera_props;
10
12
  const prm = (permitsData || []);
11
13
  // -------------------------------------------------- funtions
12
14
  const isPermitted = (perm) => {
@@ -67,6 +69,6 @@ export function useAuth() {
67
69
  setAccessToken,
68
70
  setRefreshToken,
69
71
  logout,
70
- ...ctx.authera_props,
72
+ ...authera_props,
71
73
  };
72
74
  }
package/dist/index.d.ts CHANGED
@@ -1,13 +1,5 @@
1
1
  import { customeFunc, storagesNames } from "./helper/storage";
2
- export interface AuthHookSettings<T extends string> {
3
- backendUrl: string;
4
- storage: storagesNames | customeFunc;
5
- tokenType: "jwt";
6
- refreshStrategy: "silent";
7
- fallback_401_url: string;
8
- on_after_login?: (response_data: any) => void;
9
- on_after_step?: (step_key: string) => void;
10
- }
2
+ import { type AuthHookSettings } from "./helper/types";
11
3
  export default function AuthHook<T extends string>(props: AuthHookSettings<T>): {
12
4
  createAuthProvider: (children: React.ReactNode) => React.ReactNode;
13
5
  useAuth: () => {
@@ -34,6 +26,6 @@ export default function AuthHook<T extends string>(props: AuthHookSettings<T>):
34
26
  setRefreshToken: (token: string) => void;
35
27
  logout: () => void;
36
28
  };
37
- LoginScenario: () => import("react/jsx-runtime").JSX.Element;
29
+ LoginScenario: import("react/jsx-runtime").JSX.Element;
38
30
  };
39
31
  export { default as AuthGuard } from "./web/guard";
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ export default function AuthHook(props) {
13
13
  return {
14
14
  createAuthProvider: (children) => (_jsx(AuthProvider, { storage: storage, authera_props: props, children: children })),
15
15
  useAuth: () => useAuth(),
16
- LoginScenario: () => (_jsx(LoginForm, { on_after_login: props.on_after_login, on_after_step: props.on_after_step })),
16
+ LoginScenario: (_jsx(LoginForm, { on_after_login: props.on_after_login, on_after_step: props.on_after_step, backendUrl: props.backendUrl })),
17
17
  };
18
18
  }
19
19
  export { default as AuthGuard } from "./web/guard";
@@ -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
  }
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import type { customeFunc as storageFunc } from "../helper/storage";
3
- import { type AuthHookSettings } from "..";
3
+ import { type AuthHookSettings } from "../helper/types";
4
4
  interface AuthProviderProps<T extends string> {
5
5
  children: React.ReactNode;
6
6
  storage: storageFunc;
@@ -1,6 +1,7 @@
1
1
  interface LoginFormProps {
2
2
  on_after_login?: (response_data: any) => void;
3
3
  on_after_step?: (step_key: string) => void;
4
+ backendUrl: string;
4
5
  }
5
- export default function LoginForm({ on_after_login, on_after_step, }: LoginFormProps): import("react/jsx-runtime").JSX.Element;
6
+ export default function LoginForm({ on_after_login, on_after_step, backendUrl, }: LoginFormProps): import("react/jsx-runtime").JSX.Element;
6
7
  export {};
package/dist/web/login.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
3
  import axios from "axios";
3
4
  import { convertFromSchema } from "minimal-form";
@@ -5,21 +6,21 @@ import EasyForm from "minimal-form";
5
6
  import { useEffect, useState } from "react";
6
7
  import { useForm } from "react-hook-form";
7
8
  import { useAuth } from "../hooks/useAuth";
8
- export default function LoginForm({ on_after_login, on_after_step, }) {
9
+ export default function LoginForm({ on_after_login, on_after_step, backendUrl, }) {
9
10
  const [steps, stepsHnadler] = useState();
10
11
  const [activeStep, activeStepHandler] = useState();
11
12
  const [loading, loadingHandler] = useState(true);
12
13
  const [userID, userIDHandler] = useState("");
13
14
  const [stepPayload, stepPayloadHandler] = useState({});
14
15
  const { handleSubmit, control } = useForm();
15
- const { backendUrl, setUserData, setPermits } = useAuth();
16
+ const { setUserData, setPermits } = useAuth();
16
17
  const request = axios.create({
17
18
  baseURL: backendUrl,
18
19
  });
19
20
  // fetch data from steps
20
21
  useEffect(() => {
21
22
  async function fetchSteps() {
22
- const response = await request.get("options");
23
+ const response = await request.get("options/");
23
24
  const data = Object.entries(response.data).map(([opt, schema]) => ({
24
25
  name: opt,
25
26
  structure: convertFromSchema(schema),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "authera",
3
- "version": "1.2.8",
3
+ "version": "2.0.2",
4
4
  "description": "this project is a simple auth hook for react",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",