@noxickon/onyx 6.1.2 → 6.1.3
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,76 +1,89 @@
|
|
|
1
1
|
import { createCompoundContext as e } from "../../internal/context/createCompoundContext/createCompoundContext.js";
|
|
2
2
|
import { c as t } from "react/compiler-runtime";
|
|
3
|
-
import {
|
|
4
|
-
import { jsx as
|
|
3
|
+
import { useCallback as n, useEffect as r, useRef as i, useState as a } from "react";
|
|
4
|
+
import { jsx as o } from "react/jsx-runtime";
|
|
5
5
|
//#region src/context/Auth/Auth.tsx
|
|
6
|
-
var
|
|
7
|
-
function
|
|
8
|
-
if (e
|
|
9
|
-
let t = e
|
|
6
|
+
var s = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new WeakMap(), l = 1;
|
|
7
|
+
function u(e) {
|
|
8
|
+
if (typeof e != "object" || !e) return !1;
|
|
9
|
+
let t = e;
|
|
10
|
+
return t.name === "AbortError" || t.networkError?.name === "AbortError";
|
|
11
|
+
}
|
|
12
|
+
function d(e) {
|
|
13
|
+
if (e === null) return s;
|
|
14
|
+
let t = e, n = c.get(t);
|
|
10
15
|
if (n) return n;
|
|
11
16
|
let r = e.permissions ?? [], i = new Set(r);
|
|
12
|
-
return
|
|
17
|
+
return c.set(t, i), i;
|
|
13
18
|
}
|
|
14
|
-
var { Provider:
|
|
15
|
-
function
|
|
16
|
-
let [
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
var { Provider: f, useRequiredContext: p } = e("OxAuthProvider");
|
|
20
|
+
function m({ children: e, fetchUser: t, initialUser: s, onLogout: c, performLogout: d, refreshIntervalMs: p, revalidateOnFocus: m = !1 }) {
|
|
21
|
+
let [h, g] = a(s ?? null), [_, v] = a(s === void 0), [y, b] = a(!1), [x, S] = a(null), C = i(t), w = i(d), T = i(c), E = i(s ?? null), D = i(0), O = i(null);
|
|
22
|
+
r(() => {
|
|
23
|
+
C.current = t, w.current = d, T.current = c;
|
|
19
24
|
});
|
|
20
|
-
let
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
25
|
+
let k = n(async () => {
|
|
26
|
+
let e = async (t) => {
|
|
27
|
+
O.current?.abort();
|
|
28
|
+
let n = new AbortController();
|
|
29
|
+
O.current = n;
|
|
30
|
+
let r = ++D.current;
|
|
31
|
+
b(!0);
|
|
32
|
+
try {
|
|
33
|
+
let e = await C.current(n.signal);
|
|
34
|
+
if (n.signal.aborted || r !== D.current) return;
|
|
35
|
+
g(e), E.current = e, S(null);
|
|
36
|
+
} catch (i) {
|
|
37
|
+
if (n.signal.aborted || r !== D.current) return;
|
|
38
|
+
if (u(i) && t < l) {
|
|
39
|
+
await e(t + 1);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
S(i), console.error("[OxAuthProvider] refresh failed", i);
|
|
43
|
+
} finally {
|
|
44
|
+
r === D.current && (v(!1), b(!1));
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
await e(0);
|
|
48
|
+
}, []);
|
|
49
|
+
return r(() => {
|
|
50
|
+
k();
|
|
51
|
+
}, [k]), r(() => {
|
|
52
|
+
if (p === void 0) return;
|
|
41
53
|
let e, t = () => {
|
|
42
54
|
e !== void 0 && (globalThis.clearInterval(e), e = void 0);
|
|
43
55
|
}, n = () => {
|
|
44
56
|
t(), e = globalThis.setInterval(() => {
|
|
45
|
-
|
|
46
|
-
},
|
|
57
|
+
k();
|
|
58
|
+
}, p);
|
|
47
59
|
}, r = () => {
|
|
48
60
|
document.visibilityState === "visible" ? n() : t();
|
|
49
61
|
};
|
|
50
62
|
return document.visibilityState === "visible" && n(), document.addEventListener("visibilitychange", r), () => {
|
|
51
63
|
t(), document.removeEventListener("visibilitychange", r);
|
|
52
64
|
};
|
|
53
|
-
}, [
|
|
54
|
-
if (!
|
|
65
|
+
}, [p, k]), r(() => {
|
|
66
|
+
if (!m) return;
|
|
55
67
|
let e = () => {
|
|
56
|
-
document.visibilityState === "visible" &&
|
|
68
|
+
document.visibilityState === "visible" && k();
|
|
57
69
|
}, t = () => {
|
|
58
|
-
|
|
70
|
+
k();
|
|
59
71
|
};
|
|
60
72
|
return document.addEventListener("visibilitychange", e), globalThis.addEventListener("online", t), () => {
|
|
61
73
|
document.removeEventListener("visibilitychange", e), globalThis.removeEventListener("online", t);
|
|
62
74
|
};
|
|
63
|
-
}, [
|
|
75
|
+
}, [m, k]), /* @__PURE__ */ o(f, {
|
|
64
76
|
value: {
|
|
65
|
-
user:
|
|
66
|
-
isAuthenticated:
|
|
67
|
-
isLoading:
|
|
68
|
-
isRefreshing:
|
|
69
|
-
|
|
77
|
+
user: h,
|
|
78
|
+
isAuthenticated: h !== null,
|
|
79
|
+
isLoading: _,
|
|
80
|
+
isRefreshing: y,
|
|
81
|
+
error: x,
|
|
82
|
+
refresh: k,
|
|
70
83
|
logout: async () => {
|
|
71
|
-
|
|
84
|
+
O.current?.abort(), D.current++, g(null), E.current = null, v(!1), b(!1), S(null), T.current?.();
|
|
72
85
|
try {
|
|
73
|
-
await
|
|
86
|
+
await w.current?.();
|
|
74
87
|
} catch (e) {
|
|
75
88
|
console.error("[OxAuthProvider] performLogout failed", e);
|
|
76
89
|
}
|
|
@@ -79,25 +92,25 @@ function d({ children: e, fetchUser: t, initialUser: o, onLogout: s, performLogo
|
|
|
79
92
|
children: e
|
|
80
93
|
});
|
|
81
94
|
}
|
|
82
|
-
function
|
|
83
|
-
return
|
|
95
|
+
function h() {
|
|
96
|
+
return p("useOxAuth");
|
|
84
97
|
}
|
|
85
|
-
function
|
|
86
|
-
let { user: e } =
|
|
98
|
+
function g() {
|
|
99
|
+
let { user: e } = h();
|
|
87
100
|
if (e === null) throw Error("useOxAuthUser must be used inside <OxAuthRequired> or in components that only render when authenticated");
|
|
88
101
|
return e;
|
|
89
102
|
}
|
|
90
|
-
function
|
|
91
|
-
let n = t(3), { user: r } =
|
|
92
|
-
return n[0] !== e || n[1] !== r ? (i =
|
|
103
|
+
function _(e) {
|
|
104
|
+
let n = t(3), { user: r } = h(), i;
|
|
105
|
+
return n[0] !== e || n[1] !== r ? (i = d(r).has(e), n[0] = e, n[1] = r, n[2] = i) : i = n[2], i;
|
|
93
106
|
}
|
|
94
|
-
function
|
|
95
|
-
let { children: t, fallback: n, loading: r } = e, i = n === void 0 ? null : n, a = r === void 0 ? null : r, { isAuthenticated: o, isLoading: s } =
|
|
107
|
+
function v(e) {
|
|
108
|
+
let { children: t, fallback: n, loading: r } = e, i = n === void 0 ? null : n, a = r === void 0 ? null : r, { isAuthenticated: o, isLoading: s } = h();
|
|
96
109
|
return s ? a : o ? t : i;
|
|
97
110
|
}
|
|
98
|
-
function
|
|
99
|
-
let { children: t, fallback: n, loading: r } = e, i = n === void 0 ? null : n, a = r === void 0 ? null : r, { isAuthenticated: o, isLoading: s } =
|
|
111
|
+
function y(e) {
|
|
112
|
+
let { children: t, fallback: n, loading: r } = e, i = n === void 0 ? null : n, a = r === void 0 ? null : r, { isAuthenticated: o, isLoading: s } = h();
|
|
100
113
|
return s ? a : o ? i : t;
|
|
101
114
|
}
|
|
102
115
|
//#endregion
|
|
103
|
-
export {
|
|
116
|
+
export { m as OxAuthProvider, v as OxAuthRequired, y as OxGuestOnly, h as useOxAuth, g as useOxAuthUser, _ as useOxPermission };
|
|
@@ -10,6 +10,8 @@ interface OxAuthProviderProps {
|
|
|
10
10
|
revalidateOnFocus?: boolean;
|
|
11
11
|
}
|
|
12
12
|
interface OxAuthContextValue {
|
|
13
|
+
/** Last refresh failure — session state unknown, NOT "logged out". */
|
|
14
|
+
error: unknown;
|
|
13
15
|
isAuthenticated: boolean;
|
|
14
16
|
isLoading: boolean;
|
|
15
17
|
isRefreshing: boolean;
|