@arkitektbedriftene/fe-lib 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.
- package/dist/oidc.es.js +54 -51
- package/package.json +1 -1
package/dist/oidc.es.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var v = Object.defineProperty;
|
|
2
2
|
var R = (t, e, r) => e in t ? v(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
|
|
3
3
|
var g = (t, e, r) => R(t, typeof e != "symbol" ? e + "" : e, r);
|
|
4
|
-
import { jsx as
|
|
4
|
+
import { jsx as w } from "react/jsx-runtime";
|
|
5
5
|
import { createContext as I, useContext as k, useMemo as U, useEffect as f, useState as L, useRef as x, useCallback as d } from "react";
|
|
6
6
|
import { UserManager as P } from "oidc-client-ts";
|
|
7
7
|
export * from "oidc-client-ts";
|
|
@@ -21,35 +21,35 @@ const E = I(
|
|
|
21
21
|
}) => {
|
|
22
22
|
const [e, r] = T("impersonationState", {
|
|
23
23
|
defaultValue: {}
|
|
24
|
-
}),
|
|
24
|
+
}), n = U(() => ({
|
|
25
25
|
accessToken: e == null ? void 0 : e.accessToken,
|
|
26
26
|
userInfo: e == null ? void 0 : e.userInfo,
|
|
27
27
|
setImpersonation: (o, i) => {
|
|
28
28
|
r({ accessToken: o, userInfo: i });
|
|
29
29
|
}
|
|
30
30
|
}), []);
|
|
31
|
-
return /* @__PURE__ */
|
|
31
|
+
return /* @__PURE__ */ w(E.Provider, { value: n, children: t });
|
|
32
32
|
}, q = (t) => {
|
|
33
33
|
const { setImpersonation: e } = b();
|
|
34
34
|
f(() => {
|
|
35
|
-
const { search: r } = window.location,
|
|
35
|
+
const { search: r } = window.location, n = new URLSearchParams(r).get(
|
|
36
36
|
"impersonateAccessToken"
|
|
37
37
|
);
|
|
38
|
-
if (
|
|
39
|
-
const o = y(
|
|
40
|
-
e(
|
|
38
|
+
if (n && e) {
|
|
39
|
+
const o = y(n);
|
|
40
|
+
e(n, o), t();
|
|
41
41
|
}
|
|
42
42
|
}, []);
|
|
43
43
|
};
|
|
44
44
|
function B(t) {
|
|
45
|
-
return JSON.parse(t).map((
|
|
45
|
+
return JSON.parse(t).map((n) => {
|
|
46
46
|
const [
|
|
47
47
|
o,
|
|
48
48
|
i,
|
|
49
49
|
u,
|
|
50
50
|
a,
|
|
51
51
|
l
|
|
52
|
-
] =
|
|
52
|
+
] = n.split("|"), m = a.split(",");
|
|
53
53
|
return {
|
|
54
54
|
CustomerExternalId: o,
|
|
55
55
|
CustomerFirmId: i,
|
|
@@ -83,11 +83,14 @@ class W {
|
|
|
83
83
|
const e = localStorage.getItem(this.storageKey);
|
|
84
84
|
if (e) {
|
|
85
85
|
const r = JSON.parse(e);
|
|
86
|
-
if (r.impersonationToken && r.impersonatedUser)
|
|
86
|
+
if (r.impersonationToken && r.impersonatedUser) {
|
|
87
|
+
if (Math.floor(Date.now() / 1e3) >= r.impersonatedUser.exp)
|
|
88
|
+
throw new Error("Impersonation token has expired");
|
|
87
89
|
return r;
|
|
90
|
+
}
|
|
88
91
|
}
|
|
89
92
|
} catch (e) {
|
|
90
|
-
console.error("Failed to load impersonation from storage:", e);
|
|
93
|
+
console.error("Failed to load impersonation from storage:", e), this.clearImpersonation();
|
|
91
94
|
}
|
|
92
95
|
return null;
|
|
93
96
|
}
|
|
@@ -131,11 +134,11 @@ class W {
|
|
|
131
134
|
*/
|
|
132
135
|
setImpersonation(e) {
|
|
133
136
|
try {
|
|
134
|
-
const
|
|
137
|
+
const n = {
|
|
135
138
|
impersonatedUser: y(e),
|
|
136
139
|
impersonationToken: e
|
|
137
140
|
};
|
|
138
|
-
localStorage.setItem(this.storageKey, JSON.stringify(
|
|
141
|
+
localStorage.setItem(this.storageKey, JSON.stringify(n));
|
|
139
142
|
} catch (r) {
|
|
140
143
|
console.error("Failed to decode impersonation token:", r);
|
|
141
144
|
}
|
|
@@ -150,10 +153,10 @@ class W {
|
|
|
150
153
|
* Handle impersonation callback from URL parameters
|
|
151
154
|
*/
|
|
152
155
|
handleImpersonationCallback(e) {
|
|
153
|
-
const
|
|
154
|
-
if (!
|
|
156
|
+
const n = new URL(e).searchParams.get("impersonateAccessToken");
|
|
157
|
+
if (!n)
|
|
155
158
|
throw new Error("Missing url param 'impersonateAccessToken'");
|
|
156
|
-
this.setImpersonation(
|
|
159
|
+
this.setImpersonation(n);
|
|
157
160
|
}
|
|
158
161
|
}
|
|
159
162
|
const O = ({
|
|
@@ -161,7 +164,7 @@ const O = ({
|
|
|
161
164
|
context: e,
|
|
162
165
|
children: r
|
|
163
166
|
}) => {
|
|
164
|
-
const [
|
|
167
|
+
const [n, o] = L({
|
|
165
168
|
user: null,
|
|
166
169
|
isLoading: !0,
|
|
167
170
|
isAuthenticated: !1,
|
|
@@ -171,26 +174,26 @@ const O = ({
|
|
|
171
174
|
f(() => {
|
|
172
175
|
i.current || (i.current = !0, (async () => {
|
|
173
176
|
try {
|
|
174
|
-
const
|
|
177
|
+
const s = await t.getUser();
|
|
175
178
|
o({
|
|
176
|
-
user:
|
|
179
|
+
user: s,
|
|
177
180
|
isLoading: !1,
|
|
178
|
-
isAuthenticated:
|
|
181
|
+
isAuthenticated: s ? !s.expired : !1,
|
|
179
182
|
isError: !1,
|
|
180
183
|
error: null
|
|
181
184
|
});
|
|
182
|
-
} catch (
|
|
185
|
+
} catch (s) {
|
|
183
186
|
o({
|
|
184
187
|
user: null,
|
|
185
188
|
isLoading: !1,
|
|
186
189
|
isAuthenticated: !1,
|
|
187
190
|
isError: !0,
|
|
188
|
-
error:
|
|
191
|
+
error: s instanceof Error ? s : new Error("Unknown error during auth")
|
|
189
192
|
});
|
|
190
193
|
}
|
|
191
194
|
})());
|
|
192
195
|
}, [t]), f(() => {
|
|
193
|
-
const
|
|
196
|
+
const s = (p) => {
|
|
194
197
|
o({
|
|
195
198
|
user: p,
|
|
196
199
|
isLoading: !1,
|
|
@@ -199,52 +202,52 @@ const O = ({
|
|
|
199
202
|
error: null
|
|
200
203
|
});
|
|
201
204
|
};
|
|
202
|
-
t.events.addUserLoaded(
|
|
205
|
+
t.events.addUserLoaded(s);
|
|
203
206
|
const c = () => {
|
|
204
207
|
o({
|
|
205
|
-
...
|
|
208
|
+
...n,
|
|
206
209
|
user: null,
|
|
207
210
|
isAuthenticated: !1
|
|
208
211
|
});
|
|
209
212
|
};
|
|
210
213
|
t.events.addUserUnloaded(c);
|
|
211
|
-
const
|
|
214
|
+
const S = (p) => {
|
|
212
215
|
o({
|
|
213
|
-
...
|
|
216
|
+
...n,
|
|
214
217
|
isLoading: !1,
|
|
215
218
|
isError: !0,
|
|
216
219
|
error: p
|
|
217
220
|
});
|
|
218
221
|
};
|
|
219
|
-
return t.events.addSilentRenewError(
|
|
220
|
-
t.events.removeUserLoaded(
|
|
222
|
+
return t.events.addSilentRenewError(S), () => {
|
|
223
|
+
t.events.removeUserLoaded(s), t.events.removeUserUnloaded(c), t.events.removeSilentRenewError(S);
|
|
221
224
|
};
|
|
222
225
|
}, [t]);
|
|
223
226
|
const u = d(async () => {
|
|
224
|
-
const
|
|
227
|
+
const s = await t.signinCallback();
|
|
225
228
|
return o({
|
|
226
|
-
user:
|
|
229
|
+
user: s ?? null,
|
|
227
230
|
isLoading: !1,
|
|
228
|
-
isAuthenticated:
|
|
231
|
+
isAuthenticated: s ? !s.expired : !1,
|
|
229
232
|
isError: !1,
|
|
230
233
|
error: null
|
|
231
|
-
}),
|
|
234
|
+
}), s ?? void 0;
|
|
232
235
|
}, [t]), a = d(
|
|
233
|
-
async (
|
|
236
|
+
async (s) => {
|
|
234
237
|
try {
|
|
235
|
-
await t.signinRedirect(
|
|
238
|
+
await t.signinRedirect(s);
|
|
236
239
|
} catch (c) {
|
|
237
240
|
console.error(c);
|
|
238
241
|
}
|
|
239
242
|
},
|
|
240
243
|
[t]
|
|
241
244
|
), l = d(
|
|
242
|
-
async (
|
|
245
|
+
async (s) => await t.signinPopup(s),
|
|
243
246
|
[t]
|
|
244
247
|
), m = d(
|
|
245
|
-
async (
|
|
248
|
+
async (s) => {
|
|
246
249
|
try {
|
|
247
|
-
return await t.signinSilent(
|
|
250
|
+
return await t.signinSilent(s);
|
|
248
251
|
} catch (c) {
|
|
249
252
|
return o({
|
|
250
253
|
user: null,
|
|
@@ -257,17 +260,17 @@ const O = ({
|
|
|
257
260
|
},
|
|
258
261
|
[t]
|
|
259
262
|
), h = d(
|
|
260
|
-
async (
|
|
263
|
+
async (s) => {
|
|
261
264
|
try {
|
|
262
|
-
await t.signoutRedirect(
|
|
265
|
+
await t.signoutRedirect(s);
|
|
263
266
|
} catch (c) {
|
|
264
267
|
console.error(c);
|
|
265
268
|
}
|
|
266
269
|
},
|
|
267
270
|
[t]
|
|
268
|
-
),
|
|
271
|
+
), C = U(
|
|
269
272
|
() => ({
|
|
270
|
-
state:
|
|
273
|
+
state: n,
|
|
271
274
|
handleSigninCallback: u,
|
|
272
275
|
redirectToSignin: a,
|
|
273
276
|
signinSilent: m,
|
|
@@ -275,7 +278,7 @@ const O = ({
|
|
|
275
278
|
logout: h
|
|
276
279
|
}),
|
|
277
280
|
[
|
|
278
|
-
|
|
281
|
+
n,
|
|
279
282
|
u,
|
|
280
283
|
a,
|
|
281
284
|
m,
|
|
@@ -283,30 +286,30 @@ const O = ({
|
|
|
283
286
|
h
|
|
284
287
|
]
|
|
285
288
|
);
|
|
286
|
-
return /* @__PURE__ */
|
|
287
|
-
},
|
|
289
|
+
return /* @__PURE__ */ w(e.Provider, { value: C, children: r });
|
|
290
|
+
}, A = (t) => {
|
|
288
291
|
const e = k(t);
|
|
289
292
|
if (!e)
|
|
290
293
|
throw new Error("useAuthContext must be used within an AuthProvider");
|
|
291
294
|
return e;
|
|
292
295
|
}, F = (t) => {
|
|
293
|
-
const { state: e } =
|
|
296
|
+
const { state: e } = A(t);
|
|
294
297
|
return e;
|
|
295
298
|
}, K = (t, e) => {
|
|
296
|
-
const { state: r, handleSigninCallback:
|
|
299
|
+
const { state: r, handleSigninCallback: n } = A(t), o = x(!1);
|
|
297
300
|
return f(() => {
|
|
298
|
-
o.current || (o.current = !0,
|
|
301
|
+
o.current || (o.current = !0, n().then(
|
|
299
302
|
(i) => new Promise(
|
|
300
303
|
(u) => setTimeout(() => u(i), 0)
|
|
301
304
|
)
|
|
302
305
|
).then((i) => e == null ? void 0 : e(i)));
|
|
303
|
-
}, [
|
|
306
|
+
}, [n]), r;
|
|
304
307
|
}, X = (t) => {
|
|
305
308
|
const e = I(null);
|
|
306
309
|
return {
|
|
307
310
|
AuthContext: e,
|
|
308
|
-
AuthProvider: ({ children: a }) => /* @__PURE__ */
|
|
309
|
-
useAuthContext: () =>
|
|
311
|
+
AuthProvider: ({ children: a }) => /* @__PURE__ */ w(O, { userManager: t, context: e, children: a }),
|
|
312
|
+
useAuthContext: () => A(e),
|
|
310
313
|
useAuthState: () => F(e),
|
|
311
314
|
useSigninCallback: (a) => K(e, a),
|
|
312
315
|
getAccessToken: async () => {
|