@logora/debate 0.4.83 → 0.4.84
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.
|
@@ -1,104 +1,107 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as
|
|
3
|
-
import { useConfig as
|
|
4
|
-
import { useAuthInterceptor as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
1
|
+
import { jsx as A, Fragment as O } from "react/jsx-runtime";
|
|
2
|
+
import { useState as k, useEffect as C } from "react";
|
|
3
|
+
import { useConfig as T } from "../../data/config_provider/useConfig.js";
|
|
4
|
+
import { useAuthInterceptor as I } from "../use_auth/useAuthInterceptor.js";
|
|
5
|
+
import { useAuth as S } from "../use_auth/useAuth.js";
|
|
6
|
+
import { authTokenHandler as q } from "../use_auth/authTokenHandler.js";
|
|
7
|
+
import { useAuthActions as B } from "../use_auth/useAuthActions.js";
|
|
8
|
+
import { useAuthRequired as D } from "../../hooks/use_auth_required/useAuthRequired.js";
|
|
9
|
+
import { AuthProviderFactory as F } from "../providers/AuthProviderFactory.js";
|
|
10
|
+
import { OnboardingModal as J } from "../../user/onboarding_modal/OnboardingModal.js";
|
|
11
|
+
import { saveOnboardingBeforeLogin as M } from "../../user/onboarding_modal/useOnboarding.js";
|
|
11
12
|
import { httpClient as d } from "../../data/axios_client/httpClient.js";
|
|
12
|
-
const
|
|
13
|
+
const j = (e) => {
|
|
13
14
|
const t = e.replace(/-/g, "+").replace(/_/g, "/"), a = t.padEnd(t.length + (4 - t.length % 4) % 4, "=");
|
|
14
15
|
return new TextDecoder().decode(Uint8Array.from(atob(a), (r) => r.charCodeAt(0)));
|
|
15
|
-
},
|
|
16
|
+
}, x = (e) => {
|
|
16
17
|
if (!e || typeof e != "string")
|
|
17
18
|
return null;
|
|
18
19
|
const t = e.split(".");
|
|
19
20
|
if (t.length < 2)
|
|
20
21
|
return null;
|
|
21
22
|
try {
|
|
22
|
-
return JSON.parse(
|
|
23
|
+
return JSON.parse(j(t[1]));
|
|
23
24
|
} catch {
|
|
24
25
|
return null;
|
|
25
26
|
}
|
|
26
|
-
},
|
|
27
|
+
}, z = (e, t) => {
|
|
27
28
|
if (!e || typeof e != "object")
|
|
28
29
|
return {};
|
|
29
30
|
const a = t || {}, r = (u) => {
|
|
30
31
|
const o = a[u];
|
|
31
|
-
return typeof o == "string" && o.length > 0 ? o.split(".").reduce((
|
|
32
|
+
return typeof o == "string" && o.length > 0 ? o.split(".").reduce((i, c) => i == null ? i : i[c], e) : e[u];
|
|
32
33
|
};
|
|
33
34
|
return {
|
|
34
35
|
first_name: r("first_name"),
|
|
35
36
|
last_name: r("last_name"),
|
|
36
37
|
image_url: r("image_url")
|
|
37
38
|
};
|
|
38
|
-
},
|
|
39
|
-
const u = "logora_user_token", o =
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
39
|
+
}, ee = ({ authUrl: e, authType: t, provider: a, assertion: r }) => {
|
|
40
|
+
const u = "logora_user_token", o = T();
|
|
41
|
+
I(d, e, u);
|
|
42
|
+
const i = z(
|
|
43
|
+
x(r),
|
|
43
44
|
o.auth?.userProfileMapping
|
|
44
|
-
), [
|
|
45
|
+
), [c, m] = k(!1), { setAuthError: b } = S(), { getToken: P, removeToken: U, fetchToken: y } = q(
|
|
45
46
|
d,
|
|
46
47
|
e,
|
|
47
48
|
u
|
|
48
|
-
), { loginUser:
|
|
49
|
+
), { loginUser: g, logoutUser: E, fetchUser: p } = B(
|
|
49
50
|
d,
|
|
50
51
|
e,
|
|
51
52
|
u
|
|
52
|
-
),
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}, []),
|
|
53
|
+
), w = D();
|
|
54
|
+
C(() => {
|
|
55
|
+
h();
|
|
56
|
+
}, []), C(() => {
|
|
56
57
|
if (typeof window < "u")
|
|
57
|
-
return window.addEventListener("logora:authentication:require",
|
|
58
|
-
window.removeEventListener("logora:authentication:require",
|
|
58
|
+
return window.addEventListener("logora:authentication:require", w), window.addEventListener("logora:authentication:refresh", h), () => {
|
|
59
|
+
window.removeEventListener("logora:authentication:require", w), window.removeEventListener("logora:authentication:refresh", h);
|
|
59
60
|
};
|
|
60
61
|
}, []);
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
64
|
-
const
|
|
65
|
-
|
|
62
|
+
const h = () => {
|
|
63
|
+
const s = v(), n = P();
|
|
64
|
+
if (n) {
|
|
65
|
+
const f = n.session_id;
|
|
66
|
+
s.isSameUser(f) ? p() : (U(), _(s));
|
|
66
67
|
} else
|
|
67
|
-
|
|
68
|
-
},
|
|
69
|
-
if (
|
|
70
|
-
const
|
|
71
|
-
if (
|
|
68
|
+
_(s);
|
|
69
|
+
}, _ = (s) => {
|
|
70
|
+
if (s.shouldInitAuth()) {
|
|
71
|
+
const n = s.getAuthorizationParams();
|
|
72
|
+
if (n) {
|
|
72
73
|
if (t !== "social" && t !== "oauth2_server" && o.auth?.showOnboardingBeforeLogin === !0) {
|
|
73
|
-
|
|
74
|
+
y({ ...n, create_user: !1 }).then(() => p()).catch((l) => {
|
|
75
|
+
l?.response?.data?.error_description === "user_not_found" ? m(!0) : b(l);
|
|
76
|
+
});
|
|
74
77
|
return;
|
|
75
78
|
}
|
|
76
|
-
|
|
79
|
+
g(n);
|
|
77
80
|
}
|
|
78
81
|
} else
|
|
79
|
-
|
|
80
|
-
},
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
},
|
|
84
|
-
return /* @__PURE__ */
|
|
85
|
-
|
|
82
|
+
E();
|
|
83
|
+
}, L = (s, n) => {
|
|
84
|
+
const l = v().getAuthorizationParams();
|
|
85
|
+
M(o.shortname, n), m(!1), g(l);
|
|
86
|
+
}, v = () => F.create(t, a, r);
|
|
87
|
+
return /* @__PURE__ */ A(O, { children: c && /* @__PURE__ */ A(
|
|
88
|
+
J,
|
|
86
89
|
{
|
|
87
90
|
pendingAuth: !0,
|
|
88
|
-
onConsentConfirmed:
|
|
91
|
+
onConsentConfirmed: L,
|
|
89
92
|
showCloseButton: o.auth?.allowCloseOnboardingBeforeLogin === !0,
|
|
90
|
-
onClose: () =>
|
|
93
|
+
onClose: () => m(!1),
|
|
91
94
|
showTerms: o.auth?.hideCgu !== !0,
|
|
92
95
|
showEmailConsent: o.auth?.showEmailConsent,
|
|
93
|
-
initialFirstName:
|
|
94
|
-
initialLastName:
|
|
95
|
-
initialImageUrl:
|
|
96
|
+
initialFirstName: i.first_name,
|
|
97
|
+
initialLastName: i.last_name,
|
|
98
|
+
initialImageUrl: i.image_url,
|
|
96
99
|
termsUrl: o.provider?.cguUrl || "https://www.logora.com/blog-posts/cgu",
|
|
97
100
|
privacyUrl: o.provider?.privacyUrl || "https://www.logora.com/blog-posts/privacy-policy"
|
|
98
101
|
}
|
|
99
102
|
) });
|
|
100
103
|
};
|
|
101
104
|
export {
|
|
102
|
-
|
|
103
|
-
|
|
105
|
+
ee as AuthInitializer,
|
|
106
|
+
x as decodeJwtPayload
|
|
104
107
|
};
|