@putkoff/abstract-utilities 0.1.210 → 0.1.212
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
CHANGED
|
@@ -143,6 +143,17 @@ function isLoggedIn() {
|
|
|
143
143
|
const tok = getToken();
|
|
144
144
|
return !!tok && !isTokenExpired(tok !== null && tok !== void 0 ? tok : "");
|
|
145
145
|
}
|
|
146
|
+
function removeToken() {
|
|
147
|
+
let is_logged = isLoggedIn();
|
|
148
|
+
if (is_logged) {
|
|
149
|
+
callStorage('removeItem', "token");
|
|
150
|
+
}
|
|
151
|
+
is_logged = isLoggedIn();
|
|
152
|
+
if (is_logged) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
146
157
|
/**
|
|
147
158
|
* Add a Bearer Authorization header.
|
|
148
159
|
* A shallow copy of headers is returned so callers can keep chaining.
|
|
@@ -159,7 +170,7 @@ function requireToken() {
|
|
|
159
170
|
const tok = getToken();
|
|
160
171
|
if (!tok || isTokenExpired(tok)) {
|
|
161
172
|
console.warn("→ No token or expired token, redirecting to login…");
|
|
162
|
-
|
|
173
|
+
removeToken();
|
|
163
174
|
window.location.href = '/';
|
|
164
175
|
throw new Error("Redirecting to login…");
|
|
165
176
|
}
|
|
@@ -1711,6 +1722,7 @@ exports.normalizeUrl = normalizeUrl;
|
|
|
1711
1722
|
exports.parseResult = parseResult;
|
|
1712
1723
|
exports.processKeywords = processKeywords;
|
|
1713
1724
|
exports.readJsonFile = readJsonFile;
|
|
1725
|
+
exports.removeToken = removeToken;
|
|
1714
1726
|
exports.requireToken = requireToken;
|
|
1715
1727
|
exports.safeGlobalProp = safeGlobalProp;
|
|
1716
1728
|
exports.safeStorage = safeStorage;
|