authera 1.1.3 → 1.2.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/helper/context.d.ts +2 -1
- package/dist/hooks/useAuth.d.ts +6 -1
- package/dist/hooks/useAuth.js +1 -2
- package/dist/index.d.ts +7 -1
- package/dist/index.js +2 -2
- package/dist/web/index.d.ts +3 -2
- package/dist/web/index.js +2 -2
- package/dist/web/login.d.ts +1 -5
- package/dist/web/login.js +5 -5
- package/package.json +1 -1
package/dist/helper/context.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import { type AuthHookSettings } from "..";
|
|
2
3
|
export type userBaseData<T extends string> = {
|
|
3
4
|
id: string;
|
|
4
5
|
username: string;
|
|
5
6
|
permits: T[];
|
|
6
7
|
};
|
|
7
8
|
export interface AuthContextValueType<T extends string> {
|
|
8
|
-
|
|
9
|
+
authera_props: AuthHookSettings<T>;
|
|
9
10
|
userData: userBaseData<T>;
|
|
10
11
|
setUserData: (value: userBaseData<T>) => void;
|
|
11
12
|
}
|
package/dist/hooks/useAuth.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { userBaseData } from "../helper/context";
|
|
2
2
|
export declare function useAuth<T extends string>(): {
|
|
3
|
+
backendUrl: string;
|
|
4
|
+
storage: import("../helper/storage").storagesNames | import("../helper/storage").customeFunc;
|
|
5
|
+
tokenType: "jwt";
|
|
6
|
+
refreshStrategy: "silent";
|
|
7
|
+
fallback_401_url: string;
|
|
8
|
+
go_after_login_url: string;
|
|
3
9
|
permits: T[];
|
|
4
10
|
isPermitted: (perm: T) => boolean;
|
|
5
11
|
on: (perm: T, callback: () => void, fallback?: () => void) => void;
|
|
@@ -7,6 +13,5 @@ export declare function useAuth<T extends string>(): {
|
|
|
7
13
|
addPermits: (permits: T[]) => void;
|
|
8
14
|
removePermits: (permits: T[]) => void;
|
|
9
15
|
setUserData: (userData: userBaseData<T>) => void;
|
|
10
|
-
fallback_401_url: string;
|
|
11
16
|
isPermittedAll: (perms: T[]) => boolean;
|
|
12
17
|
};
|
package/dist/hooks/useAuth.js
CHANGED
|
@@ -8,7 +8,6 @@ export function useAuth() {
|
|
|
8
8
|
// -------------------------------------------------- data
|
|
9
9
|
const { permits: permitsData } = ctx.userData;
|
|
10
10
|
const prm = (permitsData || []);
|
|
11
|
-
const fallback_401_url = ctx.fallback_401_url;
|
|
12
11
|
// -------------------------------------------------- funtions
|
|
13
12
|
const isPermitted = (perm) => {
|
|
14
13
|
return prm.includes(perm);
|
|
@@ -50,7 +49,7 @@ export function useAuth() {
|
|
|
50
49
|
addPermits,
|
|
51
50
|
removePermits,
|
|
52
51
|
setUserData,
|
|
53
|
-
fallback_401_url,
|
|
54
52
|
isPermittedAll,
|
|
53
|
+
...ctx.authera_props,
|
|
55
54
|
};
|
|
56
55
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,10 +5,17 @@ export interface AuthHookSettings<T extends string> {
|
|
|
5
5
|
tokenType: "jwt";
|
|
6
6
|
refreshStrategy: "silent";
|
|
7
7
|
fallback_401_url: string;
|
|
8
|
+
go_after_login_url: string;
|
|
8
9
|
}
|
|
9
10
|
export default function AuthHook<T extends string>(props: AuthHookSettings<T>): {
|
|
10
11
|
createAuthProvider: (children: React.ReactNode) => React.ReactNode;
|
|
11
12
|
useAuth: () => {
|
|
13
|
+
backendUrl: string;
|
|
14
|
+
storage: storagesNames | customeFunc;
|
|
15
|
+
tokenType: "jwt";
|
|
16
|
+
refreshStrategy: "silent";
|
|
17
|
+
fallback_401_url: string;
|
|
18
|
+
go_after_login_url: string;
|
|
12
19
|
permits: T[];
|
|
13
20
|
isPermitted: (perm: T) => boolean;
|
|
14
21
|
on: (perm: T, callback: () => void, fallback?: (() => void) | undefined) => void;
|
|
@@ -16,7 +23,6 @@ export default function AuthHook<T extends string>(props: AuthHookSettings<T>):
|
|
|
16
23
|
addPermits: (permits: T[]) => void;
|
|
17
24
|
removePermits: (permits: T[]) => void;
|
|
18
25
|
setUserData: (userData: import("./helper/context").userBaseData<T>) => void;
|
|
19
|
-
fallback_401_url: string;
|
|
20
26
|
isPermittedAll: (perms: T[]) => boolean;
|
|
21
27
|
};
|
|
22
28
|
LoginScenario: () => import("react/jsx-runtime").JSX.Element;
|
package/dist/index.js
CHANGED
|
@@ -11,9 +11,9 @@ export default function AuthHook(props) {
|
|
|
11
11
|
storage = name2storage(storage);
|
|
12
12
|
// create backend data
|
|
13
13
|
return {
|
|
14
|
-
createAuthProvider: (children) => (_jsx(AuthProvider, { storage: storage,
|
|
14
|
+
createAuthProvider: (children) => (_jsx(AuthProvider, { storage: storage, authera_props: props, children: children })),
|
|
15
15
|
useAuth: () => useAuth(),
|
|
16
|
-
LoginScenario: () => _jsx(LoginForm, {
|
|
16
|
+
LoginScenario: () => _jsx(LoginForm, {}),
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
export { default as AuthGuard } from "./web/guard";
|
package/dist/web/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { customeFunc as storageFunc } from "../helper/storage";
|
|
3
|
+
import { type AuthHookSettings } from "..";
|
|
3
4
|
interface AuthProviderProps<T extends string> {
|
|
4
5
|
children: React.ReactNode;
|
|
5
6
|
storage: storageFunc;
|
|
6
|
-
|
|
7
|
+
authera_props: AuthHookSettings<T>;
|
|
7
8
|
}
|
|
8
|
-
export default function AuthProvider<T extends string>({ children, storage,
|
|
9
|
+
export default function AuthProvider<T extends string>({ children, storage, authera_props, }: AuthProviderProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
9
10
|
export {};
|
package/dist/web/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { AuthContext } from "../helper/context";
|
|
4
|
-
export default function AuthProvider({ children, storage,
|
|
4
|
+
export default function AuthProvider({ children, storage, authera_props, }) {
|
|
5
5
|
/**
|
|
6
6
|
* Context Provider
|
|
7
7
|
*/
|
|
@@ -10,5 +10,5 @@ export default function AuthProvider({ children, storage, fallback_401_url, }) {
|
|
|
10
10
|
const setUserData = (value) => {
|
|
11
11
|
storage.set("userData", value);
|
|
12
12
|
};
|
|
13
|
-
return (_jsx(Provider, { value: { userData, setUserData,
|
|
13
|
+
return (_jsx(Provider, { value: { userData, setUserData, authera_props }, children: children }));
|
|
14
14
|
}
|
package/dist/web/login.d.ts
CHANGED
package/dist/web/login.js
CHANGED
|
@@ -5,19 +5,19 @@ import EasyForm from "minimal-form";
|
|
|
5
5
|
import { useEffect, useState } from "react";
|
|
6
6
|
import { useForm } from "react-hook-form";
|
|
7
7
|
import { useAuth } from "../hooks/useAuth";
|
|
8
|
-
export default function LoginForm(
|
|
8
|
+
export default function LoginForm() {
|
|
9
9
|
const [steps, stepsHnadler] = useState();
|
|
10
10
|
const [activeStep, activeStepHandler] = useState();
|
|
11
11
|
const [loading, loadingHandler] = useState(true);
|
|
12
12
|
const { handleSubmit, control } = useForm();
|
|
13
|
-
const {
|
|
13
|
+
const { go_after_login_url, backendUrl } = useAuth();
|
|
14
14
|
const request = axios.create({
|
|
15
|
-
baseURL,
|
|
15
|
+
baseURL: backendUrl,
|
|
16
16
|
});
|
|
17
17
|
// fetch data from steps
|
|
18
18
|
useEffect(() => {
|
|
19
19
|
async function fetchSteps() {
|
|
20
|
-
const response = await request.get("/options");
|
|
20
|
+
const response = await request.get("validate/options");
|
|
21
21
|
const data = Object.entries(response.data).map(([opt, schema]) => ({
|
|
22
22
|
name: opt,
|
|
23
23
|
structure: convertFromSchema(schema),
|
|
@@ -37,7 +37,7 @@ export default function LoginForm({ baseURL }) {
|
|
|
37
37
|
}
|
|
38
38
|
// if response say authenticate is finished
|
|
39
39
|
else if (response.status === 200) {
|
|
40
|
-
window.location.href =
|
|
40
|
+
window.location.href = go_after_login_url;
|
|
41
41
|
}
|
|
42
42
|
// if response say have a wrong in this request
|
|
43
43
|
else if (response.status === 400) {
|