authera 1.2.8-test → 1.2.8-test-3
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 +1 -1
- package/dist/helper/types.d.ts +10 -0
- package/dist/helper/types.js +1 -0
- package/dist/index.d.ts +1 -9
- package/dist/web/index.d.ts +1 -1
- package/dist/web/login.js +26 -24
- package/package.json +1 -1
package/dist/helper/context.d.ts
CHANGED
|
@@ -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 {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import { customeFunc, storagesNames } from "./helper/storage";
|
|
2
|
-
|
|
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: () => {
|
package/dist/web/index.d.ts
CHANGED
|
@@ -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;
|
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,34 +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
|
-
console.log("user logined with", response.data.user);
|
|
50
|
-
setUserData(response.data.user);
|
|
51
|
-
setPermits(response.data.user.permits);
|
|
52
|
-
if (on_after_login)
|
|
53
|
-
on_after_login(response.data);
|
|
54
|
-
}
|
|
55
|
-
// if response say have a wrong in this request
|
|
56
|
-
else if (response.status === 400) {
|
|
57
|
-
activeStepHandler(steps?.[0]);
|
|
58
|
-
}
|
|
59
|
-
userIDHandler(response.data.user_id);
|
|
60
|
-
stepPayloadHandler(response.data.payload);
|
|
61
63
|
};
|
|
62
64
|
// loading check
|
|
63
65
|
if (loading)
|