@djangocfg/api 2.1.264 → 2.1.266

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/auth.cjs CHANGED
@@ -4472,6 +4472,17 @@ var useTwoFactorSetup = /* @__PURE__ */ __name((options = {}) => {
4472
4472
 
4473
4473
  // src/auth/hooks/useTwoFactorStatus.ts
4474
4474
  var import_react10 = require("react");
4475
+ function extractErrorMessage(err, fallback) {
4476
+ if (err instanceof APIError3) {
4477
+ const body = err.response;
4478
+ if (typeof body?.error === "string") return body.error;
4479
+ if (typeof body?.detail === "string") return body.detail;
4480
+ return err.message;
4481
+ }
4482
+ if (err instanceof Error) return err.message;
4483
+ return fallback;
4484
+ }
4485
+ __name(extractErrorMessage, "extractErrorMessage");
4475
4486
  var useTwoFactorStatus = /* @__PURE__ */ __name(() => {
4476
4487
  const [isLoading, setIsLoading] = (0, import_react10.useState)(false);
4477
4488
  const [error, setError] = (0, import_react10.useState)(null);
@@ -4497,7 +4508,7 @@ var useTwoFactorStatus = /* @__PURE__ */ __name(() => {
4497
4508
  setHas2FAEnabled(response.has_2fa_enabled);
4498
4509
  authLogger.info("2FA status:", response.has_2fa_enabled ? "enabled" : "disabled");
4499
4510
  } catch (err) {
4500
- const errorMessage = err instanceof Error ? err.message : "Failed to fetch 2FA status";
4511
+ const errorMessage = extractErrorMessage(err, "Failed to fetch 2FA status");
4501
4512
  authLogger.error("Failed to fetch 2FA status:", err);
4502
4513
  setError(errorMessage);
4503
4514
  } finally {
@@ -4519,7 +4530,7 @@ var useTwoFactorStatus = /* @__PURE__ */ __name(() => {
4519
4530
  authLogger.info("2FA disabled successfully");
4520
4531
  return true;
4521
4532
  } catch (err) {
4522
- const errorMessage = err instanceof Error ? err.message : "Invalid verification code";
4533
+ const errorMessage = extractErrorMessage(err, "Invalid verification code");
4523
4534
  authLogger.error("Failed to disable 2FA:", err);
4524
4535
  setError(errorMessage);
4525
4536
  return false;