authera 1.2.8-test-3 → 1.2.8-test-5

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.
@@ -6,8 +6,10 @@ export function useAuth() {
6
6
  if (!ctx)
7
7
  throw new Error("useAuth must be used within an AuthContext");
8
8
  // -------------------------------------------------- data
9
- const { permits: permitsData, ...user } = ctx.userData;
9
+ const { permits: permitsData = [], ...user } = (ctx.userData ||
10
+ {});
10
11
  const prm = (permitsData || []);
12
+ console.trace();
11
13
  // -------------------------------------------------- funtions
12
14
  const isPermitted = (perm) => {
13
15
  return prm.includes(perm);
package/dist/web/login.js CHANGED
@@ -30,36 +30,33 @@ export default function LoginForm({ on_after_login, on_after_step, }) {
30
30
  }
31
31
  fetchSteps();
32
32
  }, []);
33
- const onSubmit = (data) => {
33
+ const onSubmit = async (data) => {
34
34
  // valudate step and send data to server
35
- request
36
- .post("validate/" + activeStep.name, {
35
+ const response = await request.post("validate/" + activeStep.name, {
37
36
  options: data,
38
37
  payload: stepPayload,
39
38
  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);
62
39
  });
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(response.data);
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);
63
60
  };
64
61
  // loading check
65
62
  if (loading)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "authera",
3
- "version": "1.2.8-test-3",
3
+ "version": "1.2.8-test-5",
4
4
  "description": "this project is a simple auth hook for react",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -43,4 +43,4 @@
43
43
  "minimal-form": "^2.8.1",
44
44
  "react-hook-form": "^7.66.0"
45
45
  }
46
- }
46
+ }