@putkoff/abstract-utilities 0.1.211 → 0.1.213

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/esm/index.js CHANGED
@@ -143,7 +143,7 @@ function isLoggedIn() {
143
143
  function removeToken() {
144
144
  let is_logged = isLoggedIn();
145
145
  if (is_logged) {
146
- localStorage.removeItem("token");
146
+ callStorage('removeItem', "token");
147
147
  }
148
148
  is_logged = isLoggedIn();
149
149
  if (is_logged) {
@@ -167,7 +167,7 @@ function requireToken() {
167
167
  const tok = getToken();
168
168
  if (!tok || isTokenExpired(tok)) {
169
169
  console.warn("→ No token or expired token, redirecting to login…");
170
- localStorage.removeItem("token");
170
+ removeToken();
171
171
  window.location.href = '/';
172
172
  throw new Error("Redirecting to login…");
173
173
  }
@@ -185,16 +185,13 @@ function isTokenExpired(token) {
185
185
  }
186
186
  /** Convenience wrapper: return username from the JWT (or null). */
187
187
  function currentUsername() {
188
- const tok = getToken();
189
- if (!tok)
190
- return null;
191
- try {
192
- const { username } = decodeJwt(tok);
193
- return username !== null && username !== void 0 ? username : null;
194
- }
195
- catch (_a) {
196
- return null;
188
+ const token = getToken();
189
+ let uName = null;
190
+ if (token) {
191
+ const decodedJwt = decodeJwt(token) || {};
192
+ uName = (decodedJwt === null || decodedJwt === void 0 ? void 0 : decodedJwt.username) || null;
197
193
  }
194
+ return uName;
198
195
  }
199
196
  function currentUsernames() {
200
197
  var _a;