@ichaingo/with-login 1.4.65 → 1.4.68
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/index.js +34 -34
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx as m, jsxs as
|
|
3
|
-
import
|
|
4
|
-
import { useLocale as
|
|
2
|
+
import { jsx as m, jsxs as y } from "react/jsx-runtime";
|
|
3
|
+
import I, { createContext as M, useState as w, useRef as N, useCallback as c, useEffect as p, useContext as R } from "react";
|
|
4
|
+
import { useLocale as O } from "next-intl";
|
|
5
5
|
import { twMerge as $ } from "tailwind-merge";
|
|
6
|
-
import { useTheme as
|
|
6
|
+
import { useTheme as P } from "@ichaingo/next-themes";
|
|
7
7
|
import k from "js-cookie";
|
|
8
8
|
const q = () => !!k.get("id_token");
|
|
9
|
-
var
|
|
10
|
-
const C =
|
|
9
|
+
var z = /* @__PURE__ */ ((e) => (e.CLOSE_LOGIN_MODAL = "closeLoginModal", e.LOGIN_SUCCESS = "loginSuccess", e))(z || {}), A = /* @__PURE__ */ ((e) => (e.LOGIN = "login", e.REGISTER = "register", e))(A || {});
|
|
10
|
+
const C = M(void 0);
|
|
11
11
|
function F({ children: e, loginSuccessCallback: n = () => Promise.resolve() }) {
|
|
12
|
-
const [i, s] = w(!1), [l, h] = w(!1), [a, v] = w(null), _ =
|
|
13
|
-
const
|
|
12
|
+
const [i, s] = w(!1), [l, h] = w(!1), [a, v] = w(null), _ = N(/* @__PURE__ */ new Set()), u = O(), { resolvedTheme: U } = P(), r = l && U ? U : "light", L = c((o) => {
|
|
13
|
+
const t = typeof window < "u" ? window.location.href : "", g = `${process.env.NEXT_PUBLIC_AUTH_URL}/${u}/login?mode=dialog&theme=${r}&redirect_uri=${t}`, f = `${process.env.NEXT_PUBLIC_AUTH_URL}/${u}/register?mode=dialog&theme=${r}&redirect_uri=${t}`;
|
|
14
14
|
s(!0), v(o === "register" ? f : g);
|
|
15
|
-
}, [
|
|
15
|
+
}, [r, u]), d = c(() => {
|
|
16
16
|
s(!1);
|
|
17
17
|
}, []), E = c((o) => {
|
|
18
18
|
s(o);
|
|
19
19
|
}, []);
|
|
20
20
|
p(() => {
|
|
21
|
-
if (
|
|
22
|
-
const o = typeof window < "u" ? window.location.href : "",
|
|
23
|
-
v(
|
|
21
|
+
if (r) {
|
|
22
|
+
const o = typeof window < "u" ? window.location.href : "", t = `${process.env.NEXT_PUBLIC_AUTH_URL}/${u}/login?mode=dialog&theme=${r}&redirect_uri=${o}`;
|
|
23
|
+
v(t);
|
|
24
24
|
}
|
|
25
|
-
}, [
|
|
25
|
+
}, [r]), p(() => {
|
|
26
26
|
h(!0);
|
|
27
|
-
const o = (
|
|
27
|
+
const o = (t) => {
|
|
28
28
|
var g, f;
|
|
29
|
-
((g =
|
|
29
|
+
((g = t.data) == null ? void 0 : g.type) === "closeLoginModal" && d(), ((f = t.data) == null ? void 0 : f.type) === "loginSuccess" && (console.log("handleMessage", t.data.type), d(), window.location.reload());
|
|
30
30
|
};
|
|
31
31
|
return window.addEventListener("message", o), () => {
|
|
32
32
|
window.removeEventListener("message", o);
|
|
33
33
|
};
|
|
34
34
|
}, [d, n]);
|
|
35
|
-
const
|
|
35
|
+
const S = c((o) => (_.current.add(o), () => {
|
|
36
36
|
_.current.delete(o);
|
|
37
|
-
}), []),
|
|
38
|
-
({ children: o, ...
|
|
37
|
+
}), []), x = c(
|
|
38
|
+
({ children: o, ...t }) => /* @__PURE__ */ m("div", { onClick: () => L(), style: { cursor: "pointer" }, ...t, children: o }),
|
|
39
39
|
[L]
|
|
40
|
-
), T =
|
|
40
|
+
), T = I.useMemo(() => /* @__PURE__ */ m(
|
|
41
41
|
"div",
|
|
42
42
|
{
|
|
43
43
|
className: $(
|
|
44
|
-
"
|
|
45
|
-
"transition-all duration-500
|
|
46
|
-
i && "
|
|
44
|
+
" left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full h-full bg-[rgba(0,0,0,0.7)] opacity-0 z-[-1]",
|
|
45
|
+
"transition-all duration-500 zoom-in-out fixed block",
|
|
46
|
+
i && "z-99999 opacity-100"
|
|
47
47
|
),
|
|
48
48
|
children: a && /* @__PURE__ */ m(
|
|
49
49
|
"iframe",
|
|
@@ -56,11 +56,11 @@ function F({ children: e, loginSuccessCallback: n = () => Promise.resolve() }) {
|
|
|
56
56
|
title: "Login",
|
|
57
57
|
sandbox: "allow-scripts allow-forms allow-same-origin"
|
|
58
58
|
},
|
|
59
|
-
`login-iframe-${
|
|
59
|
+
`login-iframe-${r}`
|
|
60
60
|
)
|
|
61
61
|
}
|
|
62
62
|
), [
|
|
63
|
-
|
|
63
|
+
r,
|
|
64
64
|
i,
|
|
65
65
|
a
|
|
66
66
|
]), b = {
|
|
@@ -69,35 +69,35 @@ function F({ children: e, loginSuccessCallback: n = () => Promise.resolve() }) {
|
|
|
69
69
|
closeLogin: d,
|
|
70
70
|
setLoginOpen: E,
|
|
71
71
|
url: a,
|
|
72
|
-
currentTheme:
|
|
72
|
+
currentTheme: r,
|
|
73
73
|
mounted: l,
|
|
74
|
-
Trigger:
|
|
75
|
-
registerLoginSuccessCallback:
|
|
74
|
+
Trigger: x,
|
|
75
|
+
registerLoginSuccessCallback: S
|
|
76
76
|
};
|
|
77
|
-
return /* @__PURE__ */
|
|
77
|
+
return /* @__PURE__ */ y(C.Provider, { value: b, children: [
|
|
78
78
|
e,
|
|
79
79
|
T
|
|
80
80
|
] });
|
|
81
81
|
}
|
|
82
|
-
function
|
|
83
|
-
const e =
|
|
82
|
+
function B() {
|
|
83
|
+
const e = R(C);
|
|
84
84
|
if (e === void 0)
|
|
85
85
|
throw new Error("useLogin must be used within a LoginProvider");
|
|
86
86
|
return e;
|
|
87
87
|
}
|
|
88
88
|
function J({ children: e, onClick: n, ...i }) {
|
|
89
|
-
const { Trigger: s, registerLoginSuccessCallback: l } =
|
|
89
|
+
const { Trigger: s, registerLoginSuccessCallback: l } = B();
|
|
90
90
|
return p(() => {
|
|
91
91
|
if (n)
|
|
92
92
|
return l(n);
|
|
93
93
|
}, [n, l]), e ? /* @__PURE__ */ m(s, { ...i, children: e }) : null;
|
|
94
94
|
}
|
|
95
95
|
export {
|
|
96
|
-
|
|
96
|
+
z as LoginMessageType,
|
|
97
97
|
F as LoginProvider,
|
|
98
|
-
|
|
98
|
+
A as OpenLoginType,
|
|
99
99
|
J as WithLogin,
|
|
100
100
|
J as default,
|
|
101
101
|
q as isLogin,
|
|
102
|
-
|
|
102
|
+
B as useLogin
|
|
103
103
|
};
|