@versini/auth-provider 2.0.0 → 2.0.1
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 +31 -31
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { jsx as
|
|
1
|
+
import { jsx as P } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback as p, useState as U, useEffect as w, useRef as _, useLayoutEffect as z, createContext as M, useContext as F } from "react";
|
|
3
3
|
/*!
|
|
4
|
-
@versini/auth-provider v2.0.
|
|
4
|
+
@versini/auth-provider v2.0.1
|
|
5
5
|
© 2024 gizmette.com
|
|
6
6
|
*/
|
|
7
7
|
try {
|
|
8
8
|
window.__VERSINI_AUTH_CLIENT__ || (window.__VERSINI_AUTH_CLIENT__ = {
|
|
9
|
-
version: "2.0.
|
|
10
|
-
buildTime: "06/
|
|
9
|
+
version: "2.0.1",
|
|
10
|
+
buildTime: "06/18/2024 11:21 AM EDT",
|
|
11
11
|
homepage: "https://github.com/aversini/auth-client",
|
|
12
12
|
license: "MIT"
|
|
13
13
|
});
|
|
@@ -20,7 +20,7 @@ try {
|
|
|
20
20
|
try {
|
|
21
21
|
window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
|
|
22
22
|
version: "2.0.0",
|
|
23
|
-
buildTime: "06/
|
|
23
|
+
buildTime: "06/18/2024 11:21 AM EDT",
|
|
24
24
|
homepage: "https://github.com/aversini/auth-client",
|
|
25
25
|
license: "MIT"
|
|
26
26
|
});
|
|
@@ -32,7 +32,7 @@ const H = {
|
|
|
32
32
|
CLIENT_ID: "X-Auth-ClientId"
|
|
33
33
|
};
|
|
34
34
|
var D = typeof window < "u" ? z : w;
|
|
35
|
-
function
|
|
35
|
+
function A(e, t, n, r) {
|
|
36
36
|
const c = _(t);
|
|
37
37
|
D(() => {
|
|
38
38
|
c.current = t;
|
|
@@ -48,7 +48,7 @@ function N(e, t, n, r) {
|
|
|
48
48
|
};
|
|
49
49
|
}, [e, n, r]);
|
|
50
50
|
}
|
|
51
|
-
function
|
|
51
|
+
function N(e) {
|
|
52
52
|
const t = _(() => {
|
|
53
53
|
throw new Error("Cannot call an event handler while rendering.");
|
|
54
54
|
});
|
|
@@ -71,13 +71,13 @@ function E(e, t, n = {}) {
|
|
|
71
71
|
if (o === "undefined")
|
|
72
72
|
return;
|
|
73
73
|
const a = t instanceof Function ? t() : t;
|
|
74
|
-
let
|
|
74
|
+
let T;
|
|
75
75
|
try {
|
|
76
|
-
|
|
76
|
+
T = JSON.parse(o);
|
|
77
77
|
} catch (v) {
|
|
78
78
|
return console.error("Error parsing JSON:", v), a;
|
|
79
79
|
}
|
|
80
|
-
return
|
|
80
|
+
return T;
|
|
81
81
|
},
|
|
82
82
|
[n, t]
|
|
83
83
|
), u = p(() => {
|
|
@@ -90,37 +90,37 @@ function E(e, t, n = {}) {
|
|
|
90
90
|
} catch (a) {
|
|
91
91
|
return console.warn(`Error reading localStorage key “${e}”:`, a), o;
|
|
92
92
|
}
|
|
93
|
-
}, [t, e, l]), [h,
|
|
93
|
+
}, [t, e, l]), [h, g] = U(() => r ? u() : t instanceof Function ? t() : t), k = N((o) => {
|
|
94
94
|
I && console.warn(
|
|
95
95
|
`Tried setting localStorage key “${e}” even though environment is not a client`
|
|
96
96
|
);
|
|
97
97
|
try {
|
|
98
98
|
const a = o instanceof Function ? o(u()) : o;
|
|
99
|
-
window.localStorage.setItem(e, c(a)),
|
|
99
|
+
window.localStorage.setItem(e, c(a)), g(a), window.dispatchEvent(new StorageEvent("local-storage", { key: e }));
|
|
100
100
|
} catch (a) {
|
|
101
101
|
console.warn(`Error setting localStorage key “${e}”:`, a);
|
|
102
102
|
}
|
|
103
|
-
}), i =
|
|
103
|
+
}), i = N(() => {
|
|
104
104
|
I && console.warn(
|
|
105
105
|
`Tried removing localStorage key “${e}” even though environment is not a client`
|
|
106
106
|
);
|
|
107
107
|
const o = t instanceof Function ? t() : t;
|
|
108
|
-
window.localStorage.removeItem(e),
|
|
108
|
+
window.localStorage.removeItem(e), g(o), window.dispatchEvent(new StorageEvent("local-storage", { key: e }));
|
|
109
109
|
});
|
|
110
110
|
w(() => {
|
|
111
|
-
|
|
111
|
+
g(u());
|
|
112
112
|
}, [e]);
|
|
113
113
|
const y = p(
|
|
114
114
|
(o) => {
|
|
115
|
-
o.key && o.key !== e ||
|
|
115
|
+
o.key && o.key !== e || g(u());
|
|
116
116
|
},
|
|
117
117
|
[e, u]
|
|
118
118
|
);
|
|
119
|
-
return
|
|
119
|
+
return A("storage", y), A("local-storage", y), [h, k, i];
|
|
120
120
|
}
|
|
121
121
|
const J = "Oops! It looks like your session has expired. For your security, please log in again to continue.", X = "You forgot to wrap your component in <AuthProvider>.", R = {
|
|
122
122
|
dev: "https://auth.gizmette.local.com:3003",
|
|
123
|
-
prod: "https://
|
|
123
|
+
prod: "https://mylogin.gizmette.com"
|
|
124
124
|
};
|
|
125
125
|
var s = [];
|
|
126
126
|
for (var f = 0; f < 256; ++f)
|
|
@@ -128,11 +128,11 @@ for (var f = 0; f < 256; ++f)
|
|
|
128
128
|
function K(e, t = 0) {
|
|
129
129
|
return (s[e[t + 0]] + s[e[t + 1]] + s[e[t + 2]] + s[e[t + 3]] + "-" + s[e[t + 4]] + s[e[t + 5]] + "-" + s[e[t + 6]] + s[e[t + 7]] + "-" + s[e[t + 8]] + s[e[t + 9]] + "-" + s[e[t + 10]] + s[e[t + 11]] + s[e[t + 12]] + s[e[t + 13]] + s[e[t + 14]] + s[e[t + 15]]).toLowerCase();
|
|
130
130
|
}
|
|
131
|
-
var
|
|
131
|
+
var m, W = new Uint8Array(16);
|
|
132
132
|
function Y() {
|
|
133
|
-
if (!
|
|
133
|
+
if (!m && (m = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !m))
|
|
134
134
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
135
|
-
return
|
|
135
|
+
return m(W);
|
|
136
136
|
}
|
|
137
137
|
var q = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
138
138
|
const C = {
|
|
@@ -196,13 +196,13 @@ const O = () => {
|
|
|
196
196
|
const [c, l, u] = E(
|
|
197
197
|
`@@auth@@::${n}::@@access@@`,
|
|
198
198
|
""
|
|
199
|
-
), [h,
|
|
199
|
+
), [h, g, k] = E(
|
|
200
200
|
`@@auth@@::${n}::@@refresh@@`,
|
|
201
201
|
""
|
|
202
202
|
), [i, y, o] = E(
|
|
203
203
|
`@@auth@@::${n}::@@user@@`,
|
|
204
204
|
""
|
|
205
|
-
), [a,
|
|
205
|
+
), [a, T] = U({
|
|
206
206
|
isAuthenticated: !!i,
|
|
207
207
|
accessToken: c,
|
|
208
208
|
refreshToken: h,
|
|
@@ -211,14 +211,14 @@ const O = () => {
|
|
|
211
211
|
userId: ""
|
|
212
212
|
}), v = ee(i) || "";
|
|
213
213
|
w(() => {
|
|
214
|
-
v !== i && i !== "" ?
|
|
214
|
+
v !== i && i !== "" ? T({
|
|
215
215
|
isAuthenticated: !0,
|
|
216
216
|
accessToken: c,
|
|
217
217
|
refreshToken: h,
|
|
218
218
|
idToken: i,
|
|
219
219
|
logoutReason: "",
|
|
220
220
|
userId: a.userId
|
|
221
|
-
}) : v !== i && i === "" &&
|
|
221
|
+
}) : v !== i && i === "" && T({
|
|
222
222
|
isAuthenticated: !1,
|
|
223
223
|
accessToken: "",
|
|
224
224
|
refreshToken: "",
|
|
@@ -227,18 +227,18 @@ const O = () => {
|
|
|
227
227
|
userId: ""
|
|
228
228
|
});
|
|
229
229
|
}, [c, h, i, v, a.userId]);
|
|
230
|
-
const $ = async (
|
|
230
|
+
const $ = async (L, V) => {
|
|
231
231
|
var S;
|
|
232
232
|
const d = await Z({
|
|
233
233
|
params: {
|
|
234
234
|
type: r || H.ID_TOKEN,
|
|
235
|
-
username:
|
|
236
|
-
password:
|
|
235
|
+
username: L,
|
|
236
|
+
password: V,
|
|
237
237
|
sessionExpiration: t,
|
|
238
238
|
clientId: n
|
|
239
239
|
}
|
|
240
240
|
});
|
|
241
|
-
return (S = d.data) != null && S.idToken ? (y(d.data.idToken), d.data.accessToken && l(d.data.accessToken), d.data.refreshToken &&
|
|
241
|
+
return (S = d.data) != null && S.idToken ? (y(d.data.idToken), d.data.accessToken && l(d.data.accessToken), d.data.refreshToken && g(d.data.refreshToken), T({
|
|
242
242
|
isAuthenticated: !0,
|
|
243
243
|
idToken: d.data.idToken,
|
|
244
244
|
accessToken: d.data.accessToken,
|
|
@@ -247,9 +247,9 @@ const O = () => {
|
|
|
247
247
|
logoutReason: ""
|
|
248
248
|
}), !0) : !1;
|
|
249
249
|
}, b = () => {
|
|
250
|
-
u(),
|
|
250
|
+
u(), k(), o();
|
|
251
251
|
};
|
|
252
|
-
return /* @__PURE__ */
|
|
252
|
+
return /* @__PURE__ */ P(x.Provider, { value: { ...a, login: $, logout: b }, children: e });
|
|
253
253
|
}, re = (e = x) => F(e);
|
|
254
254
|
export {
|
|
255
255
|
oe as AuthProvider,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versini/auth-provider",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"publishConfig": {
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"@versini/ui-hooks": "3.0.0",
|
|
49
49
|
"uuid": "10.0.0"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "396698b2ecd3da3881a4b226a99eff3003501a27"
|
|
52
52
|
}
|