@variamosple/variamos-components 0.0.21 → 0.0.22
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.
|
@@ -10,6 +10,7 @@ interface SessionContextType {
|
|
|
10
10
|
logout: () => void;
|
|
11
11
|
}
|
|
12
12
|
export interface SessionProviderProps {
|
|
13
|
+
loginUrl: string;
|
|
13
14
|
getSessionInfo: () => Promise<ResponseModel<SessionInfoResponse>>;
|
|
14
15
|
requestLogout: () => Promise<ResponseModel<void>>;
|
|
15
16
|
requestSignIn?: (request: Credentials) => Promise<ResponseModel<singInResponse>>;
|
|
@@ -1,94 +1,97 @@
|
|
|
1
|
-
import { j as
|
|
2
|
-
import { createContext as
|
|
3
|
-
import { Events as
|
|
4
|
-
import { usePageVisibility as
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
},
|
|
8
|
-
|
|
9
|
-
},
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import { j as G } from "../jsx-runtime-Drh4NO5G.js";
|
|
2
|
+
import { createContext as K, useState as S, useEffect as T, useContext as N } from "react";
|
|
3
|
+
import { Events as R } from "../Common/Events.js";
|
|
4
|
+
import { usePageVisibility as V } from "../Hooks/usePageVisibility.js";
|
|
5
|
+
const y = K(void 0), k = "guestId", f = (d) => {
|
|
6
|
+
d && R.publish("variamosNavigate", d);
|
|
7
|
+
}, m = (d) => {
|
|
8
|
+
d && sessionStorage.setItem("authToken", d);
|
|
9
|
+
}, H = ({
|
|
10
|
+
loginUrl: d,
|
|
11
|
+
getSessionInfo: h,
|
|
12
|
+
requestSignUp: v,
|
|
13
|
+
requestSignIn: w,
|
|
14
|
+
requestSignInAsGuest: C,
|
|
15
|
+
requestLogout: P,
|
|
16
|
+
children: b
|
|
16
17
|
}) => {
|
|
17
|
-
const [
|
|
18
|
-
|
|
19
|
-
c(!0),
|
|
20
|
-
var
|
|
21
|
-
o != null && o.errorCode ?
|
|
18
|
+
const [E, t] = S(null), [j, c] = S(!0), g = !!E, x = V();
|
|
19
|
+
T(() => {
|
|
20
|
+
c(!0), h().then((o) => {
|
|
21
|
+
var i, n, a;
|
|
22
|
+
o != null && o.errorCode ? t(null) : (m((i = o == null ? void 0 : o.data) == null ? void 0 : i.authToken), t(((n = o == null ? void 0 : o.data) == null ? void 0 : n.user) ?? null), f((a = o == null ? void 0 : o.data) == null ? void 0 : a.redirect));
|
|
22
23
|
}).catch(() => {
|
|
23
|
-
|
|
24
|
+
t(null);
|
|
24
25
|
}).finally(() => c(!1));
|
|
25
|
-
}, [
|
|
26
|
-
if (
|
|
26
|
+
}, [h]), T(() => {
|
|
27
|
+
if (g && x) {
|
|
27
28
|
const o = () => {
|
|
28
|
-
|
|
29
|
-
var
|
|
30
|
-
n != null && n.errorCode ?
|
|
29
|
+
h().then((n) => {
|
|
30
|
+
var a, r, e;
|
|
31
|
+
n != null && n.errorCode ? t(null) : (m((a = n == null ? void 0 : n.data) == null ? void 0 : a.authToken), t(((r = n == null ? void 0 : n.data) == null ? void 0 : r.user) ?? null), f((e = n == null ? void 0 : n.data) == null ? void 0 : e.redirect));
|
|
31
32
|
}).catch(() => {
|
|
32
|
-
|
|
33
|
+
t(null);
|
|
33
34
|
});
|
|
34
35
|
};
|
|
35
36
|
o();
|
|
36
|
-
const
|
|
37
|
+
const i = setInterval(() => {
|
|
37
38
|
o();
|
|
38
39
|
}, 6e4);
|
|
39
|
-
return () => clearInterval(
|
|
40
|
+
return () => clearInterval(i);
|
|
40
41
|
}
|
|
41
|
-
}, [
|
|
42
|
-
const
|
|
43
|
-
if (!g)
|
|
44
|
-
throw new Error("requestSignUp is not defined.");
|
|
45
|
-
return c(!0), g(o).finally(() => c(!1));
|
|
46
|
-
}, A = (o) => {
|
|
42
|
+
}, [g, x, h]);
|
|
43
|
+
const A = (o) => {
|
|
47
44
|
if (!v)
|
|
48
|
-
throw new Error("
|
|
49
|
-
return c(!0), v(o).
|
|
50
|
-
|
|
51
|
-
return n != null && n.errorCode ? (d(null), a.withError(n.errorCode, n.message)) : (f((i = n == null ? void 0 : n.data) == null ? void 0 : i.authToken), d(((r = n == null ? void 0 : n.data) == null ? void 0 : r.user) ?? null), h((e = n == null ? void 0 : n.data) == null ? void 0 : e.redirect)), a;
|
|
52
|
-
}).catch(() => (d(null), a.withError(500, "Sign in error.")))).finally(() => c(!1));
|
|
53
|
-
}, L = () => {
|
|
45
|
+
throw new Error("requestSignUp is not defined.");
|
|
46
|
+
return c(!0), v(o).finally(() => c(!1));
|
|
47
|
+
}, L = (o) => {
|
|
54
48
|
if (!w)
|
|
49
|
+
throw new Error("requestSignIn is not defined.");
|
|
50
|
+
return c(!0), w(o).then((i) => i != null && i.errorCode ? i : h().then((n) => {
|
|
51
|
+
var a, r, e;
|
|
52
|
+
return n != null && n.errorCode ? (t(null), i.withError(n.errorCode, n.message)) : (m((a = n == null ? void 0 : n.data) == null ? void 0 : a.authToken), t(((r = n == null ? void 0 : n.data) == null ? void 0 : r.user) ?? null), f((e = n == null ? void 0 : n.data) == null ? void 0 : e.redirect)), i;
|
|
53
|
+
}).catch(() => (t(null), i.withError(500, "Sign in error.")))).finally(() => c(!1));
|
|
54
|
+
}, U = () => {
|
|
55
|
+
if (!C)
|
|
55
56
|
throw new Error("requestSignInAsGuest is not defined.");
|
|
56
57
|
c(!0);
|
|
57
|
-
const o = localStorage.getItem(
|
|
58
|
-
return
|
|
58
|
+
const o = localStorage.getItem(k);
|
|
59
|
+
return C(o).then((i) => {
|
|
59
60
|
var n;
|
|
60
|
-
return
|
|
61
|
-
var r, e,
|
|
62
|
-
return
|
|
63
|
-
}).catch(() => (
|
|
61
|
+
return i != null && i.errorCode ? i : (localStorage.setItem(k, ((n = i == null ? void 0 : i.data) == null ? void 0 : n.id) || ""), h().then((a) => {
|
|
62
|
+
var r, e, I;
|
|
63
|
+
return a != null && a.errorCode ? (t(null), i.withError(a.errorCode, a.message)) : (m((r = a == null ? void 0 : a.data) == null ? void 0 : r.authToken), t(((e = a == null ? void 0 : a.data) == null ? void 0 : e.user) ?? null), f((I = a == null ? void 0 : a.data) == null ? void 0 : I.redirect)), i;
|
|
64
|
+
}).catch(() => (t(null), i.withError(500, "Sign in error."))));
|
|
64
65
|
}).finally(() => c(!1));
|
|
65
|
-
},
|
|
66
|
-
|
|
67
|
-
sessionStorage.removeItem("authToken"), d(
|
|
66
|
+
}, q = () => {
|
|
67
|
+
P().then(() => {
|
|
68
|
+
sessionStorage.removeItem("authToken"), f(d), setTimeout(() => {
|
|
69
|
+
t(null);
|
|
70
|
+
}, 200);
|
|
68
71
|
});
|
|
69
72
|
};
|
|
70
|
-
return /* @__PURE__ */
|
|
71
|
-
|
|
73
|
+
return /* @__PURE__ */ G.jsx(
|
|
74
|
+
y.Provider,
|
|
72
75
|
{
|
|
73
76
|
value: {
|
|
74
|
-
user:
|
|
75
|
-
isAuthenticated:
|
|
76
|
-
logout:
|
|
77
|
-
signUp:
|
|
78
|
-
signIn:
|
|
79
|
-
signInAsGuest:
|
|
80
|
-
isLoading:
|
|
77
|
+
user: E,
|
|
78
|
+
isAuthenticated: g,
|
|
79
|
+
logout: q,
|
|
80
|
+
signUp: A,
|
|
81
|
+
signIn: L,
|
|
82
|
+
signInAsGuest: U,
|
|
83
|
+
isLoading: j
|
|
81
84
|
},
|
|
82
|
-
children:
|
|
85
|
+
children: b
|
|
83
86
|
}
|
|
84
87
|
);
|
|
85
|
-
},
|
|
86
|
-
const
|
|
87
|
-
if (
|
|
88
|
+
}, J = () => {
|
|
89
|
+
const d = N(y);
|
|
90
|
+
if (d === void 0)
|
|
88
91
|
throw new Error("useSession must be used within a SessionProvider");
|
|
89
|
-
return
|
|
92
|
+
return d;
|
|
90
93
|
};
|
|
91
94
|
export {
|
|
92
|
-
|
|
93
|
-
|
|
95
|
+
H as SessionProvider,
|
|
96
|
+
J as useSession
|
|
94
97
|
};
|