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