@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 v, Fragment as E } from "react/jsx-runtime";
2
- import { useState as L, useEffect as A } from "react";
3
- import { useConfig as O } from "../../data/config_provider/useConfig.js";
4
- import { useAuthInterceptor as k } from "../use_auth/useAuthInterceptor.js";
5
- import { authTokenHandler as I } from "../use_auth/authTokenHandler.js";
6
- import { useAuthActions as S } from "../use_auth/useAuthActions.js";
7
- import { useAuthRequired as T } from "../../hooks/use_auth_required/useAuthRequired.js";
8
- import { AuthProviderFactory as q } from "../providers/AuthProviderFactory.js";
9
- import { OnboardingModal as B } from "../../user/onboarding_modal/OnboardingModal.js";
10
- import { saveOnboardingBeforeLogin as D } from "../../user/onboarding_modal/useOnboarding.js";
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 F = (e) => {
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
- }, J = (e) => {
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(F(t[1]));
23
+ return JSON.parse(j(t[1]));
23
24
  } catch {
24
25
  return null;
25
26
  }
26
- }, M = (e, t) => {
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((n, l) => n == null ? n : n[l], e) : e[u];
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
- }, X = ({ authUrl: e, authType: t, provider: a, assertion: r }) => {
39
- const u = "logora_user_token", o = O();
40
- k(d, e, u);
41
- const n = M(
42
- J(r),
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
- ), [l, c] = L(!1), { getToken: _, removeToken: C } = I(
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: f, logoutUser: b, fetchUser: P } = S(
49
+ ), { loginUser: g, logoutUser: E, fetchUser: p } = B(
49
50
  d,
50
51
  e,
51
52
  u
52
- ), g = T();
53
- A(() => {
54
- m();
55
- }, []), A(() => {
53
+ ), w = D();
54
+ C(() => {
55
+ h();
56
+ }, []), C(() => {
56
57
  if (typeof window < "u")
57
- return window.addEventListener("logora:authentication:require", g), window.addEventListener("logora:authentication:refresh", m), () => {
58
- window.removeEventListener("logora:authentication:require", g), window.removeEventListener("logora:authentication:refresh", m);
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 m = () => {
62
- const i = w(), s = _();
63
- if (s) {
64
- const h = s.session_id;
65
- i.isSameUser(h) ? P() : (C(), p(i));
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
- p(i);
68
- }, p = (i) => {
69
- if (i.shouldInitAuth()) {
70
- const s = i.getAuthorizationParams();
71
- if (s) {
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
- c(!0);
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
- f(s);
79
+ g(n);
77
80
  }
78
81
  } else
79
- b();
80
- }, U = (i, s) => {
81
- const y = w().getAuthorizationParams();
82
- D(o.shortname, s), c(!1), f(y);
83
- }, w = () => q.create(t, a, r);
84
- return /* @__PURE__ */ v(E, { children: l && /* @__PURE__ */ v(
85
- B,
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: U,
91
+ onConsentConfirmed: L,
89
92
  showCloseButton: o.auth?.allowCloseOnboardingBeforeLogin === !0,
90
- onClose: () => c(!1),
93
+ onClose: () => m(!1),
91
94
  showTerms: o.auth?.hideCgu !== !0,
92
95
  showEmailConsent: o.auth?.showEmailConsent,
93
- initialFirstName: n.first_name,
94
- initialLastName: n.last_name,
95
- initialImageUrl: n.image_url,
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
- X as AuthInitializer,
103
- J as decodeJwtPayload
105
+ ee as AuthInitializer,
106
+ x as decodeJwtPayload
104
107
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logora/debate",
3
- "version": "0.4.83",
3
+ "version": "0.4.84",
4
4
  "type": "module",
5
5
  "license": "AGPL-3.0",
6
6
  "description": "Design system of @Logora made with React",