@versini/auth-provider 1.0.2 → 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.d.ts +2 -2
- package/dist/index.js +37 -37
- 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 P } 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.1
|
|
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/
|
|
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
|
});
|
|
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/
|
|
22
|
+
version: "2.0.0",
|
|
23
|
+
buildTime: "06/18/2024 11:21 AM EDT",
|
|
24
24
|
homepage: "https://github.com/aversini/auth-client",
|
|
25
25
|
license: "MIT"
|
|
26
26
|
});
|
|
@@ -29,9 +29,9 @@ 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" ?
|
|
34
|
+
var D = typeof window < "u" ? z : w;
|
|
35
35
|
function A(e, t, n, r) {
|
|
36
36
|
const c = _(t);
|
|
37
37
|
D(() => {
|
|
@@ -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]
|
|
@@ -90,7 +90,7 @@ 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, g] =
|
|
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
|
);
|
|
@@ -116,31 +116,31 @@ function f(e, t, n = {}) {
|
|
|
116
116
|
},
|
|
117
117
|
[e, u]
|
|
118
118
|
);
|
|
119
|
-
return A("storage", y), A("local-storage", y), [h,
|
|
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
|
-
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
|
}
|
|
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
|
-
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, g,
|
|
199
|
+
), [h, g, k] = 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, T] =
|
|
205
|
+
), [a, T] = U({
|
|
206
206
|
isAuthenticated: !!i,
|
|
207
207
|
accessToken: c,
|
|
208
208
|
refreshToken: h,
|
|
@@ -227,15 +227,15 @@ const U = () => {
|
|
|
227
227
|
userId: ""
|
|
228
228
|
});
|
|
229
229
|
}, [c, h, i, v, a.userId]);
|
|
230
|
-
const
|
|
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:
|
|
235
|
+
username: L,
|
|
236
236
|
password: V,
|
|
237
237
|
sessionExpiration: t,
|
|
238
|
-
|
|
238
|
+
clientId: n
|
|
239
239
|
}
|
|
240
240
|
});
|
|
241
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({
|
|
@@ -246,10 +246,10 @@ const U = () => {
|
|
|
246
246
|
userId: d.data.userId,
|
|
247
247
|
logoutReason: ""
|
|
248
248
|
}), !0) : !1;
|
|
249
|
-
},
|
|
250
|
-
u(),
|
|
249
|
+
}, b = () => {
|
|
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": "
|
|
3
|
+
"version": "2.0.1",
|
|
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": "396698b2ecd3da3881a4b226a99eff3003501a27"
|
|
52
52
|
}
|