@sanvika/auth 2.9.4 → 2.9.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/index.js +43 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -314,8 +314,22 @@ function SanvikaAuthProvider({
|
|
|
314
314
|
...opts.headers
|
|
315
315
|
};
|
|
316
316
|
const res = await fetch(url, { ...opts, headers });
|
|
317
|
-
|
|
318
|
-
|
|
317
|
+
let data;
|
|
318
|
+
try {
|
|
319
|
+
data = await res.json();
|
|
320
|
+
} catch {
|
|
321
|
+
data = {
|
|
322
|
+
success: false,
|
|
323
|
+
message: `Invalid JSON response (HTTP ${res.status})`
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
const bodySuccess = (data == null ? void 0 : data.success) === true;
|
|
327
|
+
return {
|
|
328
|
+
data,
|
|
329
|
+
success: bodySuccess,
|
|
330
|
+
ok: res.ok && (data == null ? void 0 : data.success) !== false,
|
|
331
|
+
status: res.status
|
|
332
|
+
};
|
|
319
333
|
},
|
|
320
334
|
[persistence]
|
|
321
335
|
);
|
|
@@ -866,6 +880,29 @@ function SanvikaAdminLogin({
|
|
|
866
880
|
error && /* @__PURE__ */ jsx3("p", { style: S.error, children: error })
|
|
867
881
|
] }) });
|
|
868
882
|
}
|
|
883
|
+
|
|
884
|
+
// authFetchResult.js
|
|
885
|
+
function isAuthFetchOk(response) {
|
|
886
|
+
var _a;
|
|
887
|
+
if (!response || typeof response !== "object") return false;
|
|
888
|
+
if (response.ok === true) return true;
|
|
889
|
+
return Boolean(response.success) || ((_a = response == null ? void 0 : response.data) == null ? void 0 : _a.success) === true;
|
|
890
|
+
}
|
|
891
|
+
function getAuthFetchMessage(response, fallback = "Request failed") {
|
|
892
|
+
var _a;
|
|
893
|
+
const msg = (_a = response == null ? void 0 : response.data) == null ? void 0 : _a.message;
|
|
894
|
+
return typeof msg === "string" && msg.trim() ? msg.trim() : fallback;
|
|
895
|
+
}
|
|
896
|
+
function getAuthFetchPayload(response) {
|
|
897
|
+
return (response == null ? void 0 : response.data) ?? null;
|
|
898
|
+
}
|
|
899
|
+
function getAuthFetchData(response) {
|
|
900
|
+
const payload = getAuthFetchPayload(response);
|
|
901
|
+
if (payload && typeof payload === "object" && payload.data !== void 0) {
|
|
902
|
+
return payload.data;
|
|
903
|
+
}
|
|
904
|
+
return payload;
|
|
905
|
+
}
|
|
869
906
|
export {
|
|
870
907
|
DEFAULT_AUTH_URL,
|
|
871
908
|
DEFAULT_AVATAR_SVG,
|
|
@@ -878,7 +915,11 @@ export {
|
|
|
878
915
|
SanvikaAuthProvider,
|
|
879
916
|
checkMobile,
|
|
880
917
|
deviceAwareLogin,
|
|
918
|
+
getAuthFetchData,
|
|
919
|
+
getAuthFetchMessage,
|
|
920
|
+
getAuthFetchPayload,
|
|
881
921
|
getOrCreateWebDeviceId,
|
|
922
|
+
isAuthFetchOk,
|
|
882
923
|
postLogin,
|
|
883
924
|
randomDeviceId,
|
|
884
925
|
resolveLogoutDeviceId,
|