@iblai/web-utils 1.2.10 → 1.2.12

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.ts CHANGED
@@ -814,7 +814,7 @@ declare const isWeb: () => boolean;
814
814
  declare const isNode: () => string | false;
815
815
  declare const isExpo: () => any;
816
816
  declare const isTauri: () => boolean;
817
- declare const getPlatform: () => "web" | "react-native" | "node" | "unknown";
817
+ declare const getPlatform: () => "react-native" | "web" | "node" | "unknown";
818
818
  declare const safeRequire: (moduleName: string) => any;
819
819
  declare const getNextNavigation: () => any;
820
820
 
package/dist/index.esm.js CHANGED
@@ -2761,7 +2761,7 @@ async function isDmTokenExpired(storageService) {
2761
2761
  try {
2762
2762
  const dmTokenExpires = await storageService.getItem(LOCAL_STORAGE_KEYS.DM_TOKEN_EXPIRES);
2763
2763
  if (!dmTokenExpires) {
2764
- return true;
2764
+ return false;
2765
2765
  }
2766
2766
  const expiryTime = new Date(dmTokenExpires).getTime();
2767
2767
  const currentTime = Date.now();
@@ -2991,14 +2991,23 @@ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure,
2991
2991
  }
2992
2992
  // Check JWT token expiry and force logout for protected routes
2993
2993
  if (isProtectedRoute && storageService) {
2994
+ const dmTokenInLocalStorage = await storageService.getItem(LOCAL_STORAGE_KEYS.DM_TOKEN_KEY);
2994
2995
  const dmTokenExpired = await isDmTokenExpired(storageService);
2995
- if (dmTokenExpired) {
2996
- console.log("[auth-redirect] DM token has expired, forcing logout");
2996
+ if (!dmTokenInLocalStorage || dmTokenExpired) {
2997
+ console.log();
2998
+ if (!!dmTokenInLocalStorage) {
2999
+ console.log("[auth-redirect] DM token doesn't exists");
3000
+ }
3001
+ else {
3002
+ console.log("[auth-redirect] DM token doesn't exists, forcing logout");
3003
+ }
2997
3004
  // Clear all auth-related storage keys
2998
- clearAuthCookies();
3005
+ if (!!dmTokenInLocalStorage) {
3006
+ clearAuthCookies();
3007
+ }
2999
3008
  const reason = "DM token expired";
3000
3009
  onAuthFailure === null || onAuthFailure === void 0 ? void 0 : onAuthFailure(reason);
3001
- safeRedirectToAuthSpa(undefined, undefined, true);
3010
+ safeRedirectToAuthSpa(undefined, undefined, !!dmTokenInLocalStorage); // with no dm token at all in storage, don't force logout
3002
3011
  return;
3003
3012
  }
3004
3013
  // Validate JWT token user_id
@@ -16063,7 +16072,37 @@ createApi({
16063
16072
  tagTypes: ['reports', 'reportDetail'],
16064
16073
  endpoints: (builder) => ({
16065
16074
  getReports: builder.query({
16066
- ...buildEndpointFromDmService(ReportsService.reportsPlatformsRetrieve),
16075
+ async queryFn({ key, mentor_id }) {
16076
+ var _a, _b;
16077
+ try {
16078
+ const baseUrl = getServiceUrl(SERVICES.DM);
16079
+ const authHeaders = await getHeaders(SERVICES.DM);
16080
+ const url = new URL(`/dm/api/reports/platforms/${encodeURIComponent(key)}/`, baseUrl);
16081
+ if (mentor_id) {
16082
+ url.searchParams.set('mentor_id', mentor_id);
16083
+ }
16084
+ const response = await fetch(url.toString(), {
16085
+ method: 'GET',
16086
+ headers: {
16087
+ 'Content-Type': 'application/json',
16088
+ ...(authHeaders !== null && authHeaders !== void 0 ? authHeaders : {}),
16089
+ },
16090
+ });
16091
+ const data = (await response.json());
16092
+ if (!response.ok) {
16093
+ return { error: { status: response.status, data } };
16094
+ }
16095
+ return { data };
16096
+ }
16097
+ catch (err) {
16098
+ return {
16099
+ error: {
16100
+ status: (_a = err === null || err === void 0 ? void 0 : err.status) !== null && _a !== void 0 ? _a : 500,
16101
+ data: (_b = err === null || err === void 0 ? void 0 : err.message) !== null && _b !== void 0 ? _b : 'Unknown error',
16102
+ },
16103
+ };
16104
+ }
16105
+ },
16067
16106
  providesTags: ['reports'],
16068
16107
  }),
16069
16108
  getReportDetail: builder.query({