@chemmangat/msal-next 5.3.0 → 5.3.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.d.mts CHANGED
@@ -1037,6 +1037,11 @@ interface GraphApiOptions extends RequestInit {
1037
1037
  * @default false
1038
1038
  */
1039
1039
  debug?: boolean;
1040
+ /**
1041
+ * Expected response type. Use 'blob' for binary data like images.
1042
+ * @default 'json'
1043
+ */
1044
+ responseType?: 'json' | 'blob' | 'text';
1040
1045
  }
1041
1046
  interface UseGraphApiReturn {
1042
1047
  /**
package/dist/index.d.ts CHANGED
@@ -1037,6 +1037,11 @@ interface GraphApiOptions extends RequestInit {
1037
1037
  * @default false
1038
1038
  */
1039
1039
  debug?: boolean;
1040
+ /**
1041
+ * Expected response type. Use 'blob' for binary data like images.
1042
+ * @default 'json'
1043
+ */
1044
+ responseType?: 'json' | 'blob' | 'text';
1040
1045
  }
1041
1046
  interface UseGraphApiReturn {
1042
1047
  /**
package/dist/index.js CHANGED
@@ -1430,6 +1430,7 @@ function useGraphApi() {
1430
1430
  scopes = ["User.Read"],
1431
1431
  version = "v1.0",
1432
1432
  debug = false,
1433
+ responseType = "json",
1433
1434
  ...fetchOptions
1434
1435
  } = options;
1435
1436
  try {
@@ -1455,9 +1456,16 @@ function useGraphApi() {
1455
1456
  if (response.status === 204 || response.headers.get("content-length") === "0") {
1456
1457
  return null;
1457
1458
  }
1458
- const data = await response.json();
1459
+ let data;
1460
+ if (responseType === "blob") {
1461
+ data = await response.blob();
1462
+ } else if (responseType === "text") {
1463
+ data = await response.text();
1464
+ } else {
1465
+ data = await response.json();
1466
+ }
1459
1467
  if (debug) {
1460
- console.log("[GraphAPI] Response:", data);
1468
+ console.log("[GraphAPI] Response:", responseType === "blob" ? "[Blob]" : data);
1461
1469
  }
1462
1470
  return data;
1463
1471
  } catch (error) {
@@ -1565,17 +1573,17 @@ function useUserProfile() {
1565
1573
  try {
1566
1574
  const photoBlob = await graph.get("/me/photo/$value", {
1567
1575
  scopes: ["User.Read"],
1568
- headers: {
1569
- "Content-Type": "image/jpeg"
1570
- }
1576
+ responseType: "blob"
1571
1577
  });
1572
- if (photoBlob) {
1578
+ if (photoBlob instanceof Blob && photoBlob.size > 0) {
1573
1579
  photoUrl = URL.createObjectURL(photoBlob);
1574
1580
  }
1575
1581
  } catch (photoError) {
1576
1582
  console.debug("[UserProfile] Photo not available");
1577
1583
  }
1578
1584
  const profileData = {
1585
+ ...userData,
1586
+ // spread first so explicit fields below always take precedence
1579
1587
  id: userData.id,
1580
1588
  displayName: userData.displayName,
1581
1589
  givenName: userData.givenName,
@@ -1611,9 +1619,8 @@ function useUserProfile() {
1611
1619
  accountEnabled: userData.accountEnabled,
1612
1620
  ageGroup: userData.ageGroup,
1613
1621
  userType: userData.userType,
1614
- photo: photoUrl,
1615
- ...userData
1616
- // Include any additional fields from the API
1622
+ photo: photoUrl
1623
+ // always last — blob URL must never be overwritten by raw API data
1617
1624
  };
1618
1625
  profileCache.set(cacheKey, {
1619
1626
  data: profileData,
package/dist/index.mjs CHANGED
@@ -1371,6 +1371,7 @@ function useGraphApi() {
1371
1371
  scopes = ["User.Read"],
1372
1372
  version = "v1.0",
1373
1373
  debug = false,
1374
+ responseType = "json",
1374
1375
  ...fetchOptions
1375
1376
  } = options;
1376
1377
  try {
@@ -1396,9 +1397,16 @@ function useGraphApi() {
1396
1397
  if (response.status === 204 || response.headers.get("content-length") === "0") {
1397
1398
  return null;
1398
1399
  }
1399
- const data = await response.json();
1400
+ let data;
1401
+ if (responseType === "blob") {
1402
+ data = await response.blob();
1403
+ } else if (responseType === "text") {
1404
+ data = await response.text();
1405
+ } else {
1406
+ data = await response.json();
1407
+ }
1400
1408
  if (debug) {
1401
- console.log("[GraphAPI] Response:", data);
1409
+ console.log("[GraphAPI] Response:", responseType === "blob" ? "[Blob]" : data);
1402
1410
  }
1403
1411
  return data;
1404
1412
  } catch (error) {
@@ -1506,17 +1514,17 @@ function useUserProfile() {
1506
1514
  try {
1507
1515
  const photoBlob = await graph.get("/me/photo/$value", {
1508
1516
  scopes: ["User.Read"],
1509
- headers: {
1510
- "Content-Type": "image/jpeg"
1511
- }
1517
+ responseType: "blob"
1512
1518
  });
1513
- if (photoBlob) {
1519
+ if (photoBlob instanceof Blob && photoBlob.size > 0) {
1514
1520
  photoUrl = URL.createObjectURL(photoBlob);
1515
1521
  }
1516
1522
  } catch (photoError) {
1517
1523
  console.debug("[UserProfile] Photo not available");
1518
1524
  }
1519
1525
  const profileData = {
1526
+ ...userData,
1527
+ // spread first so explicit fields below always take precedence
1520
1528
  id: userData.id,
1521
1529
  displayName: userData.displayName,
1522
1530
  givenName: userData.givenName,
@@ -1552,9 +1560,8 @@ function useUserProfile() {
1552
1560
  accountEnabled: userData.accountEnabled,
1553
1561
  ageGroup: userData.ageGroup,
1554
1562
  userType: userData.userType,
1555
- photo: photoUrl,
1556
- ...userData
1557
- // Include any additional fields from the API
1563
+ photo: photoUrl
1564
+ // always last — blob URL must never be overwritten by raw API data
1558
1565
  };
1559
1566
  profileCache.set(cacheKey, {
1560
1567
  data: profileData,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chemmangat/msal-next",
3
- "version": "5.3.0",
3
+ "version": "5.3.2",
4
4
  "description": "Production-ready Microsoft/Azure AD authentication for Next.js App Router. Zero-config setup, TypeScript-first, multi-account support, auto token refresh. The easiest way to add Microsoft login to your Next.js app.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",