varminer-app-header 2.2.4 → 2.2.5
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/AppHeader.d.ts.map +1 -1
- package/dist/index.esm.js +36 -6
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +36 -6
- package/dist/index.js.map +1 -1
- package/dist/utils/localStorage.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -472,30 +472,37 @@ function parseNestedValue(val) {
|
|
|
472
472
|
return parsePersistValue(val);
|
|
473
473
|
return val;
|
|
474
474
|
}
|
|
475
|
+
const AUTH_DEBUG = true; // set to false to disable access-token debug logs
|
|
475
476
|
/**
|
|
476
477
|
* Extract access token from persist:userdb shape: authDetails (string) → parse → auth.accessToken.
|
|
477
478
|
* Structure: { authDetails: "{\"auth\":{\"accessToken\":\"...\"}}", profileInformation: "...", _persist: "..." }
|
|
478
479
|
*/
|
|
479
480
|
function getTokenFromUserDbPersist(parsed) {
|
|
481
|
+
console.log("[header-auth] getTokenFromUserDbPersist: parsed keys", Object.keys(parsed));
|
|
480
482
|
const authDetails = parsed.authDetails;
|
|
481
483
|
const inner = parseNestedValue(authDetails);
|
|
482
484
|
const obj = typeof inner === "object" && inner !== null ? inner : null;
|
|
485
|
+
console.log("[header-auth] getTokenFromUserDbPersist: inner type", typeof inner, "obj keys", obj ? Object.keys(obj) : null);
|
|
483
486
|
if (!obj)
|
|
484
487
|
return undefined;
|
|
485
488
|
const auth = obj.auth;
|
|
486
489
|
const authObj = typeof auth === "object" && auth !== null ? auth : null;
|
|
490
|
+
console.log("[header-auth] getTokenFromUserDbPersist: authObj keys", authObj ? Object.keys(authObj) : null);
|
|
487
491
|
if (!authObj)
|
|
488
492
|
return undefined;
|
|
489
493
|
const token = authObj.accessToken ??
|
|
490
494
|
authObj.access_token ??
|
|
491
495
|
authObj.token;
|
|
492
|
-
|
|
496
|
+
const ok = typeof token === "string" && looksLikeToken(token);
|
|
497
|
+
console.log("[header-auth] getTokenFromUserDbPersist: token found", !!ok, "length", typeof token === "string" ? token.length : 0);
|
|
498
|
+
return ok ? token : undefined;
|
|
493
499
|
}
|
|
494
500
|
/**
|
|
495
501
|
* Get access token from all known storage keys (header, IAM, userdb, and plain keys).
|
|
496
502
|
* persist:userdb shape: authDetails (stringified) contains auth.accessToken.
|
|
497
503
|
*/
|
|
498
504
|
function getAccessTokenForRequest() {
|
|
505
|
+
console.log("[header-auth] getAccessTokenForRequest: start");
|
|
499
506
|
const keysToTry = [
|
|
500
507
|
PERSIST_HEADER_KEY,
|
|
501
508
|
"persist:linn-i-am",
|
|
@@ -506,6 +513,7 @@ function getAccessTokenForRequest() {
|
|
|
506
513
|
];
|
|
507
514
|
for (const key of keysToTry) {
|
|
508
515
|
const raw = localStorage.getItem(key);
|
|
516
|
+
console.log("[header-auth] getAccessTokenForRequest: key", key, "raw present", !!raw, "raw length", raw?.length ?? 0);
|
|
509
517
|
if (!raw)
|
|
510
518
|
continue;
|
|
511
519
|
const parsed = key.startsWith("persist:") ? parsePersistValue(raw) : (() => { try {
|
|
@@ -515,39 +523,59 @@ function getAccessTokenForRequest() {
|
|
|
515
523
|
return raw;
|
|
516
524
|
} })();
|
|
517
525
|
const token = findTokenInObject(parsed);
|
|
518
|
-
if (token)
|
|
526
|
+
if (token) {
|
|
527
|
+
console.log("[header-auth] getAccessTokenForRequest: token from findTokenInObject(parsed), key", key);
|
|
519
528
|
return token;
|
|
529
|
+
}
|
|
520
530
|
if (key.startsWith("persist:")) {
|
|
521
531
|
const outer = typeof parsed === "object" && parsed !== null ? parsed : null;
|
|
522
532
|
if (outer) {
|
|
523
533
|
if (key === "persist:userdb") {
|
|
524
534
|
const fromUserDb = getTokenFromUserDbPersist(outer);
|
|
525
|
-
if (fromUserDb)
|
|
535
|
+
if (fromUserDb) {
|
|
536
|
+
console.log("[header-auth] getAccessTokenForRequest: token from getTokenFromUserDbPersist");
|
|
526
537
|
return fromUserDb;
|
|
538
|
+
}
|
|
527
539
|
}
|
|
528
540
|
for (const k of Object.keys(outer)) {
|
|
529
541
|
const inner = parseNestedValue(outer[k]);
|
|
530
542
|
const t = findTokenInObject(inner);
|
|
531
|
-
if (t)
|
|
543
|
+
if (t) {
|
|
544
|
+
console.log("[header-auth] getAccessTokenForRequest: token from inner key", k);
|
|
532
545
|
return t;
|
|
546
|
+
}
|
|
533
547
|
}
|
|
534
548
|
}
|
|
535
549
|
}
|
|
536
550
|
}
|
|
537
|
-
|
|
551
|
+
const allData = getAllDataFromStorage();
|
|
552
|
+
const fallback = getAccessTokenFromAuth(allData.auth);
|
|
553
|
+
console.log("[header-auth] getAccessTokenForRequest: fallback getAllDataFromStorage().auth, token present", !!fallback);
|
|
554
|
+
return fallback;
|
|
538
555
|
}
|
|
539
556
|
const fetchProfilePictureAsBlobUrl = async (baseUrl = "http://objectstore.impact0mics.local:9012", accessTokenOverride) => {
|
|
540
557
|
try {
|
|
558
|
+
if (AUTH_DEBUG)
|
|
559
|
+
console.log("[header-auth] fetchProfilePictureAsBlobUrl: start, accessTokenOverride present", typeof accessTokenOverride === "string" && accessTokenOverride.length > 0);
|
|
541
560
|
const profilePictureUrl = getProfilePictureUrl(baseUrl);
|
|
542
|
-
if (!profilePictureUrl)
|
|
561
|
+
if (!profilePictureUrl) {
|
|
562
|
+
if (AUTH_DEBUG)
|
|
563
|
+
console.log("[header-auth] fetchProfilePictureAsBlobUrl: no profilePictureUrl, abort");
|
|
543
564
|
return null;
|
|
565
|
+
}
|
|
566
|
+
if (AUTH_DEBUG)
|
|
567
|
+
console.log("[header-auth] fetchProfilePictureAsBlobUrl: profilePictureUrl", profilePictureUrl);
|
|
544
568
|
const accessToken = (typeof accessTokenOverride === "string" && accessTokenOverride.length > 0
|
|
545
569
|
? accessTokenOverride
|
|
546
570
|
: null) ?? getAccessTokenForRequest();
|
|
571
|
+
if (AUTH_DEBUG)
|
|
572
|
+
console.log("[header-auth] fetchProfilePictureAsBlobUrl: accessToken present", !!accessToken, "length", accessToken?.length ?? 0);
|
|
547
573
|
const headers = {};
|
|
548
574
|
if (accessToken) {
|
|
549
575
|
headers["Authorization"] = `Bearer ${accessToken}`;
|
|
550
576
|
}
|
|
577
|
+
if (AUTH_DEBUG)
|
|
578
|
+
console.log("[header-auth] fetchProfilePictureAsBlobUrl: request headers", { ...headers, Authorization: headers["Authorization"] ? "Bearer ***" : "(none)" });
|
|
551
579
|
const response = await fetch(profilePictureUrl, { method: "GET", headers });
|
|
552
580
|
if (!response.ok) {
|
|
553
581
|
console.warn(`Failed to fetch profile picture: ${response.status} ${response.statusText}`);
|
|
@@ -802,7 +830,9 @@ const AppHeader = ({ language: languageProp, accessToken: accessTokenProp }) =>
|
|
|
802
830
|
// Fetch profile picture from API when component mounts or user data changes
|
|
803
831
|
React.useEffect(() => {
|
|
804
832
|
const fetchProfilePicture = async () => {
|
|
833
|
+
console.log("[header-auth] AppHeader: profile picture effect, accessTokenProp present", !!accessTokenProp);
|
|
805
834
|
const token = accessTokenProp ?? getAccessTokenForRequest();
|
|
835
|
+
console.log("[header-auth] AppHeader: token for request present", !!token, "from prop", !!accessTokenProp);
|
|
806
836
|
const blobUrl = await fetchProfilePictureAsBlobUrl(undefined, token ?? undefined);
|
|
807
837
|
if (blobUrl) {
|
|
808
838
|
// Clean up previous blob URL if it exists
|