authera 1.2.7 → 1.2.8-test-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.
- package/dist/hooks/useAuth.d.ts +1 -1
- package/dist/hooks/useAuth.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/web/login.d.ts +1 -1
- package/dist/web/login.js +26 -23
- package/package.json +1 -1
package/dist/hooks/useAuth.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare function useAuth<T extends string>(): {
|
|
|
5
5
|
tokenType: "jwt";
|
|
6
6
|
refreshStrategy: "silent";
|
|
7
7
|
fallback_401_url: string;
|
|
8
|
-
on_after_login?: () => void;
|
|
8
|
+
on_after_login?: (response_data: any) => void;
|
|
9
9
|
on_after_step?: (step_key: string) => void;
|
|
10
10
|
permits: T[];
|
|
11
11
|
isPermitted: (perm: T) => boolean;
|
package/dist/hooks/useAuth.js
CHANGED
|
@@ -8,7 +8,6 @@ export function useAuth() {
|
|
|
8
8
|
// -------------------------------------------------- data
|
|
9
9
|
const { permits: permitsData, ...user } = ctx.userData;
|
|
10
10
|
const prm = (permitsData || []);
|
|
11
|
-
console.log("userData", ctx.userData);
|
|
12
11
|
// -------------------------------------------------- funtions
|
|
13
12
|
const isPermitted = (perm) => {
|
|
14
13
|
return prm.includes(perm);
|
|
@@ -23,6 +22,7 @@ export function useAuth() {
|
|
|
23
22
|
fallback();
|
|
24
23
|
};
|
|
25
24
|
const setUserData = (userData) => {
|
|
25
|
+
console.log("userData", userData);
|
|
26
26
|
ctx.set("userData", userData);
|
|
27
27
|
};
|
|
28
28
|
const setPermits = (permits) => {
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export interface AuthHookSettings<T extends string> {
|
|
|
5
5
|
tokenType: "jwt";
|
|
6
6
|
refreshStrategy: "silent";
|
|
7
7
|
fallback_401_url: string;
|
|
8
|
-
on_after_login?: () => void;
|
|
8
|
+
on_after_login?: (response_data: any) => void;
|
|
9
9
|
on_after_step?: (step_key: string) => void;
|
|
10
10
|
}
|
|
11
11
|
export default function AuthHook<T extends string>(props: AuthHookSettings<T>): {
|
|
@@ -16,7 +16,7 @@ export default function AuthHook<T extends string>(props: AuthHookSettings<T>):
|
|
|
16
16
|
tokenType: "jwt";
|
|
17
17
|
refreshStrategy: "silent";
|
|
18
18
|
fallback_401_url: string;
|
|
19
|
-
on_after_login?: () => void;
|
|
19
|
+
on_after_login?: (response_data: any) => void;
|
|
20
20
|
on_after_step?: (step_key: string) => void;
|
|
21
21
|
permits: T[];
|
|
22
22
|
isPermitted: (perm: T) => boolean;
|
package/dist/web/login.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
interface LoginFormProps {
|
|
2
|
-
on_after_login?: () => void;
|
|
2
|
+
on_after_login?: (response_data: any) => void;
|
|
3
3
|
on_after_step?: (step_key: string) => void;
|
|
4
4
|
}
|
|
5
5
|
export default function LoginForm({ on_after_login, on_after_step, }: LoginFormProps): import("react/jsx-runtime").JSX.Element;
|
package/dist/web/login.js
CHANGED
|
@@ -19,7 +19,7 @@ export default function LoginForm({ on_after_login, on_after_step, }) {
|
|
|
19
19
|
// fetch data from steps
|
|
20
20
|
useEffect(() => {
|
|
21
21
|
async function fetchSteps() {
|
|
22
|
-
const response = await request.get("options");
|
|
22
|
+
const response = await request.get("options/");
|
|
23
23
|
const data = Object.entries(response.data).map(([opt, schema]) => ({
|
|
24
24
|
name: opt,
|
|
25
25
|
structure: convertFromSchema(schema),
|
|
@@ -30,33 +30,36 @@ export default function LoginForm({ on_after_login, on_after_step, }) {
|
|
|
30
30
|
}
|
|
31
31
|
fetchSteps();
|
|
32
32
|
}, []);
|
|
33
|
-
const onSubmit =
|
|
33
|
+
const onSubmit = (data) => {
|
|
34
34
|
// valudate step and send data to server
|
|
35
|
-
|
|
35
|
+
request
|
|
36
|
+
.post("validate/" + activeStep.name, {
|
|
36
37
|
options: data,
|
|
37
38
|
payload: stepPayload,
|
|
38
39
|
user_id: userID,
|
|
40
|
+
})
|
|
41
|
+
.then((response) => {
|
|
42
|
+
// if response say go next step
|
|
43
|
+
if (response.status === 202) {
|
|
44
|
+
const nextIndex = (steps?.findIndex((d) => d.name === activeStep?.name) || 0) + 1;
|
|
45
|
+
activeStepHandler(steps?.[nextIndex]);
|
|
46
|
+
if (on_after_step)
|
|
47
|
+
on_after_step(steps?.[nextIndex]?.name || "");
|
|
48
|
+
}
|
|
49
|
+
// if response say authenticate is finished
|
|
50
|
+
else if (response.status === 200) {
|
|
51
|
+
setUserData(response.data.user);
|
|
52
|
+
setPermits(response.data.user.permits);
|
|
53
|
+
if (on_after_login)
|
|
54
|
+
on_after_login(response.data);
|
|
55
|
+
}
|
|
56
|
+
// if response say have a wrong in this request
|
|
57
|
+
else if (response.status === 400) {
|
|
58
|
+
activeStepHandler(steps?.[0]);
|
|
59
|
+
}
|
|
60
|
+
userIDHandler(response.data.user_id);
|
|
61
|
+
stepPayloadHandler(response.data.payload);
|
|
39
62
|
});
|
|
40
|
-
// if response say go next step
|
|
41
|
-
if (response.status === 202) {
|
|
42
|
-
const nextIndex = (steps?.findIndex((d) => d.name === activeStep?.name) || 0) + 1;
|
|
43
|
-
activeStepHandler(steps?.[nextIndex]);
|
|
44
|
-
if (on_after_step)
|
|
45
|
-
on_after_step(steps?.[nextIndex]?.name || "");
|
|
46
|
-
}
|
|
47
|
-
// if response say authenticate is finished
|
|
48
|
-
else if (response.status === 200) {
|
|
49
|
-
setUserData(response.data.user);
|
|
50
|
-
setPermits(response.data.user.permits);
|
|
51
|
-
if (on_after_login)
|
|
52
|
-
on_after_login();
|
|
53
|
-
}
|
|
54
|
-
// if response say have a wrong in this request
|
|
55
|
-
else if (response.status === 400) {
|
|
56
|
-
activeStepHandler(steps?.[0]);
|
|
57
|
-
}
|
|
58
|
-
userIDHandler(response.data.user_id);
|
|
59
|
-
stepPayloadHandler(response.data.payload);
|
|
60
63
|
};
|
|
61
64
|
// loading check
|
|
62
65
|
if (loading)
|