@versini/auth-provider 1.0.2 → 2.0.0
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.d.ts +2 -2
- package/dist/index.js +46 -46
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import * as react from 'react';
|
|
|
4
4
|
type AuthProviderProps = {
|
|
5
5
|
children: React.ReactNode;
|
|
6
6
|
sessionExpiration?: string;
|
|
7
|
-
|
|
7
|
+
clientId: string;
|
|
8
8
|
accessType?: string;
|
|
9
9
|
};
|
|
10
10
|
|
|
@@ -18,7 +18,7 @@ type AuthContextProps = {
|
|
|
18
18
|
logoutReason?: string;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
declare const AuthProvider: ({ children, sessionExpiration,
|
|
21
|
+
declare const AuthProvider: ({ children, sessionExpiration, clientId, accessType, }: AuthProviderProps) => react_jsx_runtime.JSX.Element;
|
|
22
22
|
|
|
23
23
|
declare const useAuth: (context?: react.Context<AuthContextProps>) => AuthContextProps;
|
|
24
24
|
|
package/dist/index.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useCallback as p, useState as
|
|
1
|
+
import { jsx as V } from "react/jsx-runtime";
|
|
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
|
|
4
|
+
@versini/auth-provider v2.0.0
|
|
5
5
|
© 2024 gizmette.com
|
|
6
6
|
*/
|
|
7
7
|
try {
|
|
8
8
|
window.__VERSINI_AUTH_CLIENT__ || (window.__VERSINI_AUTH_CLIENT__ = {
|
|
9
|
-
version: "
|
|
10
|
-
buildTime: "06/17/2024
|
|
9
|
+
version: "2.0.0",
|
|
10
|
+
buildTime: "06/17/2024 04:39 PM EDT",
|
|
11
11
|
homepage: "https://github.com/aversini/auth-client",
|
|
12
12
|
license: "MIT"
|
|
13
13
|
});
|
|
14
14
|
} catch {
|
|
15
15
|
}
|
|
16
16
|
/*!
|
|
17
|
-
@versini/auth-common
|
|
17
|
+
@versini/auth-common v2.0.0
|
|
18
18
|
© 2024 gizmette.com
|
|
19
19
|
*/
|
|
20
20
|
try {
|
|
21
21
|
window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
|
|
22
|
-
version: "
|
|
23
|
-
buildTime: "06/17/2024
|
|
22
|
+
version: "2.0.0",
|
|
23
|
+
buildTime: "06/17/2024 04:39 PM EDT",
|
|
24
24
|
homepage: "https://github.com/aversini/auth-client",
|
|
25
25
|
license: "MIT"
|
|
26
26
|
});
|
|
@@ -29,10 +29,10 @@ try {
|
|
|
29
29
|
const H = {
|
|
30
30
|
ID_TOKEN: "id_token"
|
|
31
31
|
}, j = {
|
|
32
|
-
|
|
32
|
+
CLIENT_ID: "X-Auth-ClientId"
|
|
33
33
|
};
|
|
34
|
-
var D = typeof window < "u" ?
|
|
35
|
-
function
|
|
34
|
+
var D = typeof window < "u" ? z : w;
|
|
35
|
+
function N(e, t, n, r) {
|
|
36
36
|
const c = _(t);
|
|
37
37
|
D(() => {
|
|
38
38
|
c.current = t;
|
|
@@ -48,7 +48,7 @@ function A(e, t, n, r) {
|
|
|
48
48
|
};
|
|
49
49
|
}, [e, n, r]);
|
|
50
50
|
}
|
|
51
|
-
function
|
|
51
|
+
function A(e) {
|
|
52
52
|
const t = _(() => {
|
|
53
53
|
throw new Error("Cannot call an event handler while rendering.");
|
|
54
54
|
});
|
|
@@ -60,7 +60,7 @@ function N(e) {
|
|
|
60
60
|
}, [t]);
|
|
61
61
|
}
|
|
62
62
|
var I = typeof window > "u";
|
|
63
|
-
function
|
|
63
|
+
function E(e, t, n = {}) {
|
|
64
64
|
const { initializeWithValue: r = !0 } = n, c = p(
|
|
65
65
|
(o) => n.serializer ? n.serializer(o) : JSON.stringify(o),
|
|
66
66
|
[n]
|
|
@@ -71,13 +71,13 @@ function f(e, t, n = {}) {
|
|
|
71
71
|
if (o === "undefined")
|
|
72
72
|
return;
|
|
73
73
|
const a = t instanceof Function ? t() : t;
|
|
74
|
-
let
|
|
74
|
+
let g;
|
|
75
75
|
try {
|
|
76
|
-
|
|
76
|
+
g = JSON.parse(o);
|
|
77
77
|
} catch (v) {
|
|
78
78
|
return console.error("Error parsing JSON:", v), a;
|
|
79
79
|
}
|
|
80
|
-
return
|
|
80
|
+
return g;
|
|
81
81
|
},
|
|
82
82
|
[n, t]
|
|
83
83
|
), u = p(() => {
|
|
@@ -90,41 +90,41 @@ function f(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, T] = U(() => r ? u() : t instanceof Function ? t() : t), m = A((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)), T(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 = A(() => {
|
|
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), T(o), window.dispatchEvent(new StorageEvent("local-storage", { key: e }));
|
|
109
109
|
});
|
|
110
110
|
w(() => {
|
|
111
|
-
|
|
111
|
+
T(u());
|
|
112
112
|
}, [e]);
|
|
113
113
|
const y = p(
|
|
114
114
|
(o) => {
|
|
115
|
-
o.key && o.key !== e ||
|
|
115
|
+
o.key && o.key !== e || T(u());
|
|
116
116
|
},
|
|
117
117
|
[e, u]
|
|
118
118
|
);
|
|
119
|
-
return
|
|
119
|
+
return N("storage", y), N("local-storage", y), [h, m, 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
123
|
prod: "https://auth.gizmette.com"
|
|
124
124
|
};
|
|
125
125
|
var s = [];
|
|
126
|
-
for (var
|
|
127
|
-
s.push((
|
|
126
|
+
for (var f = 0; f < 256; ++f)
|
|
127
|
+
s.push((f + 256).toString(16).slice(1));
|
|
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
|
}
|
|
@@ -135,12 +135,12 @@ function Y() {
|
|
|
135
135
|
return k(W);
|
|
136
136
|
}
|
|
137
137
|
var q = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
138
|
-
const
|
|
138
|
+
const C = {
|
|
139
139
|
randomUUID: q
|
|
140
140
|
};
|
|
141
141
|
function B(e, t, n) {
|
|
142
|
-
if (
|
|
143
|
-
return
|
|
142
|
+
if (C.randomUUID && !t && !e)
|
|
143
|
+
return C.randomUUID();
|
|
144
144
|
e = e || {};
|
|
145
145
|
var r = e.random || (e.rng || Y)();
|
|
146
146
|
return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, K(r);
|
|
@@ -154,7 +154,7 @@ const G = process.env.NODE_ENV === "production", Q = !G, Z = async ({ params: e
|
|
|
154
154
|
method: "POST",
|
|
155
155
|
headers: {
|
|
156
156
|
"Content-Type": "application/json",
|
|
157
|
-
[j.
|
|
157
|
+
[j.CLIENT_ID]: `${e.clientId}`
|
|
158
158
|
},
|
|
159
159
|
body: JSON.stringify({ ...e, nonce: t })
|
|
160
160
|
}
|
|
@@ -177,12 +177,12 @@ function ee(e) {
|
|
|
177
177
|
t.current = e;
|
|
178
178
|
}), t.current;
|
|
179
179
|
}
|
|
180
|
-
const
|
|
180
|
+
const O = () => {
|
|
181
181
|
throw new Error(X);
|
|
182
182
|
}, x = M({
|
|
183
183
|
isAuthenticated: !1,
|
|
184
|
-
login:
|
|
185
|
-
logout:
|
|
184
|
+
login: O,
|
|
185
|
+
logout: O,
|
|
186
186
|
accessToken: void 0,
|
|
187
187
|
refreshToken: void 0,
|
|
188
188
|
idToken: void 0,
|
|
@@ -190,19 +190,19 @@ const U = () => {
|
|
|
190
190
|
}), oe = ({
|
|
191
191
|
children: e,
|
|
192
192
|
sessionExpiration: t,
|
|
193
|
-
|
|
193
|
+
clientId: n,
|
|
194
194
|
accessType: r
|
|
195
195
|
}) => {
|
|
196
|
-
const [c, l, u] =
|
|
196
|
+
const [c, l, u] = E(
|
|
197
197
|
`@@auth@@::${n}::@@access@@`,
|
|
198
198
|
""
|
|
199
|
-
), [h,
|
|
199
|
+
), [h, T, m] = E(
|
|
200
200
|
`@@auth@@::${n}::@@refresh@@`,
|
|
201
201
|
""
|
|
202
|
-
), [i, y, o] =
|
|
202
|
+
), [i, y, o] = E(
|
|
203
203
|
`@@auth@@::${n}::@@user@@`,
|
|
204
204
|
""
|
|
205
|
-
), [a,
|
|
205
|
+
), [a, g] = U({
|
|
206
206
|
isAuthenticated: !!i,
|
|
207
207
|
accessToken: c,
|
|
208
208
|
refreshToken: h,
|
|
@@ -211,14 +211,14 @@ const U = () => {
|
|
|
211
211
|
userId: ""
|
|
212
212
|
}), v = ee(i) || "";
|
|
213
213
|
w(() => {
|
|
214
|
-
v !== i && i !== "" ?
|
|
214
|
+
v !== i && i !== "" ? g({
|
|
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 === "" && g({
|
|
222
222
|
isAuthenticated: !1,
|
|
223
223
|
accessToken: "",
|
|
224
224
|
refreshToken: "",
|
|
@@ -227,18 +227,18 @@ const U = () => {
|
|
|
227
227
|
userId: ""
|
|
228
228
|
});
|
|
229
229
|
}, [c, h, i, v, a.userId]);
|
|
230
|
-
const
|
|
230
|
+
const $ = async (P, L) => {
|
|
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: P,
|
|
236
|
+
password: L,
|
|
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 && T(d.data.refreshToken), g({
|
|
242
242
|
isAuthenticated: !0,
|
|
243
243
|
idToken: d.data.idToken,
|
|
244
244
|
accessToken: d.data.accessToken,
|
|
@@ -246,10 +246,10 @@ const U = () => {
|
|
|
246
246
|
userId: d.data.userId,
|
|
247
247
|
logoutReason: ""
|
|
248
248
|
}), !0) : !1;
|
|
249
|
-
},
|
|
249
|
+
}, b = () => {
|
|
250
250
|
u(), m(), o();
|
|
251
251
|
};
|
|
252
|
-
return /* @__PURE__ */
|
|
252
|
+
return /* @__PURE__ */ V(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": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"publishConfig": {
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"react-dom": "18.3.1"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@versini/auth-common": "
|
|
47
|
+
"@versini/auth-common": "2.0.0",
|
|
48
48
|
"@versini/ui-hooks": "3.0.0",
|
|
49
49
|
"uuid": "10.0.0"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "3dbd373d2db89d99a1ca36e0bbe1bc987d8eaaae"
|
|
52
52
|
}
|