@calimero-network/mero-react 9.13.1 → 9.13.2
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.cjs +9 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +9 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -364,7 +364,7 @@ function MeroProvider({
|
|
|
364
364
|
);
|
|
365
365
|
const checkAuth = useCallback(
|
|
366
366
|
async (instance) => {
|
|
367
|
-
const accessToken =
|
|
367
|
+
const accessToken = instance.getTokenData()?.access_token;
|
|
368
368
|
if (!accessToken) return false;
|
|
369
369
|
const validate = async (token) => {
|
|
370
370
|
try {
|
|
@@ -375,11 +375,11 @@ function MeroProvider({
|
|
|
375
375
|
}
|
|
376
376
|
};
|
|
377
377
|
if (await validate(accessToken)) return true;
|
|
378
|
-
const rotated =
|
|
378
|
+
const rotated = instance.getTokenData()?.access_token;
|
|
379
379
|
if (!rotated || rotated === accessToken) return false;
|
|
380
380
|
return validate(rotated);
|
|
381
381
|
},
|
|
382
|
-
[
|
|
382
|
+
[]
|
|
383
383
|
);
|
|
384
384
|
const connectToNode = useCallback(
|
|
385
385
|
(url) => {
|
|
@@ -483,6 +483,7 @@ function MeroProvider({
|
|
|
483
483
|
const init = async () => {
|
|
484
484
|
const callback = callbackRef.current;
|
|
485
485
|
let nodeFromCallback = null;
|
|
486
|
+
let instance = null;
|
|
486
487
|
if (callback) {
|
|
487
488
|
const initiatedNodeUrl = getNodeUrl();
|
|
488
489
|
const tokenNodeUrl = getTokenNodeUrl() ?? initiatedNodeUrl;
|
|
@@ -500,15 +501,16 @@ function MeroProvider({
|
|
|
500
501
|
"[MeroProvider] OAuth callback node_url is not trusted (it does not match the node login was initiated with, nor `allowedNodeUrls`). Ignoring the callback; no tokens stored."
|
|
501
502
|
);
|
|
502
503
|
} else if (url) {
|
|
504
|
+
instance = createMeroInstance(url);
|
|
503
505
|
const decision = resolveTokenAdoption({
|
|
504
506
|
callbackAccessToken: callback.accessToken,
|
|
505
507
|
callbackRefreshToken: callback.refreshToken,
|
|
506
508
|
callbackNodeUrl: url,
|
|
507
|
-
stored:
|
|
509
|
+
stored: instance.getTokenData(),
|
|
508
510
|
storedNodeUrl: tokenNodeUrl
|
|
509
511
|
});
|
|
510
512
|
if (decision.adopt) {
|
|
511
|
-
|
|
513
|
+
instance.setTokenData(decision.tokens);
|
|
512
514
|
setTokenNodeUrl(url);
|
|
513
515
|
} else {
|
|
514
516
|
console.warn(
|
|
@@ -537,7 +539,7 @@ function MeroProvider({
|
|
|
537
539
|
if (active) setIsLoading(false);
|
|
538
540
|
return;
|
|
539
541
|
}
|
|
540
|
-
|
|
542
|
+
instance ?? (instance = createMeroInstance(savedUrl));
|
|
541
543
|
const authed = await checkAuth(instance);
|
|
542
544
|
if (!active) return;
|
|
543
545
|
if (authed) {
|
|
@@ -556,7 +558,7 @@ function MeroProvider({
|
|
|
556
558
|
return () => {
|
|
557
559
|
active = false;
|
|
558
560
|
};
|
|
559
|
-
}, [createMeroInstance, checkAuth, allowedNodeUrls,
|
|
561
|
+
}, [createMeroInstance, checkAuth, allowedNodeUrls, delegated]);
|
|
560
562
|
useEffect(() => {
|
|
561
563
|
if (!isAuthenticated || !meroRef.current) return;
|
|
562
564
|
let active = true;
|