@iblai/web-utils 1.2.10 → 1.2.11

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 CHANGED
@@ -2781,7 +2781,7 @@ async function isDmTokenExpired(storageService) {
2781
2781
  try {
2782
2782
  const dmTokenExpires = await storageService.getItem(LOCAL_STORAGE_KEYS.DM_TOKEN_EXPIRES);
2783
2783
  if (!dmTokenExpires) {
2784
- return true;
2784
+ return false;
2785
2785
  }
2786
2786
  const expiryTime = new Date(dmTokenExpires).getTime();
2787
2787
  const currentTime = Date.now();
@@ -3011,14 +3011,15 @@ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure,
3011
3011
  }
3012
3012
  // Check JWT token expiry and force logout for protected routes
3013
3013
  if (isProtectedRoute && storageService) {
3014
+ const dmTokenInLocalStorage = await storageService.getItem(LOCAL_STORAGE_KEYS.DM_TOKEN_KEY);
3014
3015
  const dmTokenExpired = await isDmTokenExpired(storageService);
3015
- if (dmTokenExpired) {
3016
+ if (!dmTokenInLocalStorage || dmTokenExpired) {
3016
3017
  console.log("[auth-redirect] DM token has expired, forcing logout");
3017
3018
  // Clear all auth-related storage keys
3018
3019
  clearAuthCookies();
3019
3020
  const reason = "DM token expired";
3020
3021
  onAuthFailure === null || onAuthFailure === void 0 ? void 0 : onAuthFailure(reason);
3021
- safeRedirectToAuthSpa(undefined, undefined, true);
3022
+ safeRedirectToAuthSpa(undefined, undefined, !!dmTokenInLocalStorage); // with no dm token at all in storage, don't force logout
3022
3023
  return;
3023
3024
  }
3024
3025
  // Validate JWT token user_id
@@ -16083,7 +16084,37 @@ createApi({
16083
16084
  tagTypes: ['reports', 'reportDetail'],
16084
16085
  endpoints: (builder) => ({
16085
16086
  getReports: builder.query({
16086
- ...buildEndpointFromDmService(iblaiApi.ReportsService.reportsPlatformsRetrieve),
16087
+ async queryFn({ key, mentor_id }) {
16088
+ var _a, _b;
16089
+ try {
16090
+ const baseUrl = getServiceUrl(SERVICES.DM);
16091
+ const authHeaders = await getHeaders(SERVICES.DM);
16092
+ const url = new URL(`/dm/api/reports/platforms/${encodeURIComponent(key)}/`, baseUrl);
16093
+ if (mentor_id) {
16094
+ url.searchParams.set('mentor_id', mentor_id);
16095
+ }
16096
+ const response = await fetch(url.toString(), {
16097
+ method: 'GET',
16098
+ headers: {
16099
+ 'Content-Type': 'application/json',
16100
+ ...(authHeaders !== null && authHeaders !== void 0 ? authHeaders : {}),
16101
+ },
16102
+ });
16103
+ const data = (await response.json());
16104
+ if (!response.ok) {
16105
+ return { error: { status: response.status, data } };
16106
+ }
16107
+ return { data };
16108
+ }
16109
+ catch (err) {
16110
+ return {
16111
+ error: {
16112
+ status: (_a = err === null || err === void 0 ? void 0 : err.status) !== null && _a !== void 0 ? _a : 500,
16113
+ data: (_b = err === null || err === void 0 ? void 0 : err.message) !== null && _b !== void 0 ? _b : 'Unknown error',
16114
+ },
16115
+ };
16116
+ }
16117
+ },
16087
16118
  providesTags: ['reports'],
16088
16119
  }),
16089
16120
  getReportDetail: builder.query({