@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/cjs/index.js +8 -11
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +8 -11
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
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
|
-
|
|
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
|
-
|
|
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
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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;
|