@duxweb/dvha-core 0.1.0 → 0.1.1
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/cjs/hooks/auth.cjs +1 -1
- package/dist/esm/hooks/auth.js +53 -53
- package/package.json +1 -1
package/dist/cjs/hooks/auth.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("vue"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("vue"),g=require("vue-router"),h=require("../stores/auth.cjs"),d=require("./manage.cjs");function m({onSuccess:e,onError:a}){const o=d.useManage(),s=h.useAuthStore(),r=g.useRouter(),n=f.ref(!1);return{mutate:async t=>{var c;n.value=!0;const i=await((c=o.config.authProvider)==null?void 0:c.login(t,o));if(n.value=!1,i!=null&&i.success){if(!(i!=null&&i.data))throw new Error("Login response data is undefined");e==null||e(i),s.login(i.data),r.push(o.getRoutePath(i.redirectTo||"/"));return}a==null||a(i)},isLoading:n}}function P({onSuccess:e,onError:a}){const o=d.useManage(),s=h.useAuthStore(),r=g.useRouter();return{mutate:async u=>{var i;const t=await((i=o.config.authProvider)==null?void 0:i.logout(u,o));if(t!=null&&t.success){e==null||e(t),s.logout(),r.push(o.getRoutePath(t.redirectTo||"/login"));return}a==null||a(t)}}}function w({onSuccess:e,onError:a}){const o=d.useManage(),s=h.useAuthStore(),r=g.useRouter();return{mutate:async u=>{var i;const t=await((i=o.config.authProvider)==null?void 0:i.check(u,o));if(t!=null&&t.success){if(e==null||e(t),!(t!=null&&t.data))throw new Error("Check response data is undefined");s.update(t.data);return}a==null||a(t),t!=null&&t.logout&&r.push(o.getRoutePath(t.redirectTo||"/login"))}}}function R({onSuccess:e,onError:a}){const o=d.useManage(),s=h.useAuthStore(),r=g.useRouter();return{mutate:async u=>{var i;const t=await((i=o.config.authProvider)==null?void 0:i.register(u,o));if(t!=null&&t.success){if(e==null||e(t),!(t!=null&&t.data))throw new Error("Register response data is undefined");s.login(t.data),r.push(o.getRoutePath(t.redirectTo||""));return}a==null||a(t)}}}function p({onSuccess:e,onError:a}){const o=d.useManage(),s=g.useRouter();return{mutate:async n=>{var t;const u=await((t=o.config.authProvider)==null?void 0:t.forgotPassword(n,o));if(u!=null&&u.success){e==null||e(u),u.redirectTo&&s.push(o.getRoutePath(u.redirectTo));return}a==null||a(u)}}}function v({onSuccess:e,onError:a}){const o=d.useManage(),s=g.useRouter();return{mutate:async n=>{var t;const u=await((t=o.config.authProvider)==null?void 0:t.updatePassword(n,o));if(u!=null&&u.success){e==null||e(u),u.redirectTo&&s.push(o.getRoutePath(u.redirectTo));return}a==null||a(u)}}}function T(e){const{config:a,getRoutePath:o}=d.useManage(),s=g.useRouter();return{mutate:async n=>{var t;const u=await((t=a.authProvider)==null?void 0:t.onError(n));e==null||e(u),u!=null&&u.logout&&s.push(o(u.redirectTo||"/login"))}}}function y(e){return h.useAuthStore(e).getUser()}function L(e){return h.useAuthStore(e).isLogin()}exports.useCheck=w;exports.useError=T;exports.useForgotPassword=p;exports.useGetAuth=y;exports.useIsLogin=L;exports.useLogin=m;exports.useLogout=P;exports.useRegister=R;exports.useUpdatePassword=v;
|
package/dist/esm/hooks/auth.js
CHANGED
|
@@ -1,114 +1,114 @@
|
|
|
1
|
-
import { ref as
|
|
1
|
+
import { ref as c } from "vue";
|
|
2
2
|
import { useRouter as r } from "vue-router";
|
|
3
|
-
import { useAuthStore as
|
|
3
|
+
import { useAuthStore as f } from "../stores/auth.js";
|
|
4
4
|
import { useManage as d } from "./manage.js";
|
|
5
|
-
function R({ onSuccess: e, onError:
|
|
6
|
-
const
|
|
5
|
+
function R({ onSuccess: e, onError: i }) {
|
|
6
|
+
const u = d(), n = f(), s = r(), g = c(!1);
|
|
7
7
|
return {
|
|
8
|
-
mutate: async (
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
if (
|
|
13
|
-
if (!(
|
|
8
|
+
mutate: async (t) => {
|
|
9
|
+
var h;
|
|
10
|
+
g.value = !0;
|
|
11
|
+
const o = await ((h = u.config.authProvider) == null ? void 0 : h.login(t, u));
|
|
12
|
+
if (g.value = !1, o != null && o.success) {
|
|
13
|
+
if (!(o != null && o.data))
|
|
14
14
|
throw new Error("Login response data is undefined");
|
|
15
|
-
e == null || e(
|
|
15
|
+
e == null || e(o), n.login(o.data), s.push(u.getRoutePath(o.redirectTo || "/"));
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
i == null || i(o);
|
|
19
19
|
},
|
|
20
|
-
isLoading:
|
|
20
|
+
isLoading: g
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
function v({ onSuccess: e, onError:
|
|
24
|
-
const
|
|
23
|
+
function v({ onSuccess: e, onError: i }) {
|
|
24
|
+
const u = d(), n = f(), s = r();
|
|
25
25
|
return {
|
|
26
|
-
mutate: async (
|
|
27
|
-
var
|
|
28
|
-
const t = await ((
|
|
26
|
+
mutate: async (a) => {
|
|
27
|
+
var o;
|
|
28
|
+
const t = await ((o = u.config.authProvider) == null ? void 0 : o.logout(a, u));
|
|
29
29
|
if (t != null && t.success) {
|
|
30
|
-
e == null || e(t),
|
|
30
|
+
e == null || e(t), n.logout(), s.push(u.getRoutePath(t.redirectTo || "/login"));
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
i == null || i(t);
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
-
function T({ onSuccess: e, onError:
|
|
38
|
-
const
|
|
37
|
+
function T({ onSuccess: e, onError: i }) {
|
|
38
|
+
const u = d(), n = f(), s = r();
|
|
39
39
|
return {
|
|
40
|
-
mutate: async (
|
|
41
|
-
var
|
|
42
|
-
const t = await ((
|
|
40
|
+
mutate: async (a) => {
|
|
41
|
+
var o;
|
|
42
|
+
const t = await ((o = u.config.authProvider) == null ? void 0 : o.check(a, u));
|
|
43
43
|
if (t != null && t.success) {
|
|
44
44
|
if (e == null || e(t), !(t != null && t.data))
|
|
45
45
|
throw new Error("Check response data is undefined");
|
|
46
|
-
|
|
46
|
+
n.update(t.data);
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
i == null || i(t), t != null && t.logout && s.push(u.getRoutePath(t.redirectTo || "/login"));
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
|
-
function y({ onSuccess: e, onError:
|
|
54
|
-
const
|
|
53
|
+
function y({ onSuccess: e, onError: i }) {
|
|
54
|
+
const u = d(), n = f(), s = r();
|
|
55
55
|
return {
|
|
56
|
-
mutate: async (
|
|
57
|
-
var
|
|
58
|
-
const t = await ((
|
|
56
|
+
mutate: async (a) => {
|
|
57
|
+
var o;
|
|
58
|
+
const t = await ((o = u.config.authProvider) == null ? void 0 : o.register(a, u));
|
|
59
59
|
if (t != null && t.success) {
|
|
60
60
|
if (e == null || e(t), !(t != null && t.data))
|
|
61
61
|
throw new Error("Register response data is undefined");
|
|
62
|
-
|
|
62
|
+
n.login(t.data), s.push(u.getRoutePath(t.redirectTo || ""));
|
|
63
63
|
return;
|
|
64
64
|
}
|
|
65
|
-
|
|
65
|
+
i == null || i(t);
|
|
66
66
|
}
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
|
-
function L({ onSuccess: e, onError:
|
|
70
|
-
const
|
|
69
|
+
function L({ onSuccess: e, onError: i }) {
|
|
70
|
+
const u = d(), n = r();
|
|
71
71
|
return {
|
|
72
72
|
mutate: async (g) => {
|
|
73
73
|
var t;
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
76
|
-
e == null || e(
|
|
74
|
+
const a = await ((t = u.config.authProvider) == null ? void 0 : t.forgotPassword(g, u));
|
|
75
|
+
if (a != null && a.success) {
|
|
76
|
+
e == null || e(a), a.redirectTo && n.push(u.getRoutePath(a.redirectTo));
|
|
77
77
|
return;
|
|
78
78
|
}
|
|
79
|
-
|
|
79
|
+
i == null || i(a);
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
-
function A({ onSuccess: e, onError:
|
|
84
|
-
const
|
|
83
|
+
function A({ onSuccess: e, onError: i }) {
|
|
84
|
+
const u = d(), n = r();
|
|
85
85
|
return {
|
|
86
86
|
mutate: async (g) => {
|
|
87
87
|
var t;
|
|
88
|
-
const
|
|
89
|
-
if (
|
|
90
|
-
e == null || e(
|
|
88
|
+
const a = await ((t = u.config.authProvider) == null ? void 0 : t.updatePassword(g, u));
|
|
89
|
+
if (a != null && a.success) {
|
|
90
|
+
e == null || e(a), a.redirectTo && n.push(u.getRoutePath(a.redirectTo));
|
|
91
91
|
return;
|
|
92
92
|
}
|
|
93
|
-
|
|
93
|
+
i == null || i(a);
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
97
|
function U(e) {
|
|
98
|
-
const { config:
|
|
98
|
+
const { config: i, getRoutePath: u } = d(), n = r();
|
|
99
99
|
return {
|
|
100
|
-
mutate: async (
|
|
101
|
-
var
|
|
102
|
-
const
|
|
103
|
-
e == null || e(
|
|
100
|
+
mutate: async (g) => {
|
|
101
|
+
var t;
|
|
102
|
+
const a = await ((t = i.authProvider) == null ? void 0 : t.onError(g));
|
|
103
|
+
e == null || e(a), a != null && a.logout && n.push(u(a.redirectTo || "/login"));
|
|
104
104
|
}
|
|
105
105
|
};
|
|
106
106
|
}
|
|
107
107
|
function x(e) {
|
|
108
|
-
return
|
|
108
|
+
return f(e).getUser();
|
|
109
109
|
}
|
|
110
110
|
function F(e) {
|
|
111
|
-
return
|
|
111
|
+
return f(e).isLogin();
|
|
112
112
|
}
|
|
113
113
|
export {
|
|
114
114
|
T as useCheck,
|