supaapps-auth 3.2.0 → 3.2.2
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.d.ts +1 -0
- package/dist/index.js +9 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -68,6 +68,7 @@ function generateCodeChallenge(verifier) {
|
|
|
68
68
|
// src/AuthManager.ts
|
|
69
69
|
var AuthManager = class _AuthManager {
|
|
70
70
|
static instance = null;
|
|
71
|
+
tokenExpiryLeewaySeconds = 10;
|
|
71
72
|
authServer;
|
|
72
73
|
realmName;
|
|
73
74
|
redirectUri;
|
|
@@ -141,13 +142,17 @@ var AuthManager = class _AuthManager {
|
|
|
141
142
|
async checkAccessToken(isInitilization = false) {
|
|
142
143
|
const accessToken = localStorage.getItem("access_token");
|
|
143
144
|
if (accessToken && this.isTokenExpired(accessToken)) {
|
|
145
|
+
console.info(
|
|
146
|
+
"[AuthManager] Access token expired or near expiry; refreshing."
|
|
147
|
+
);
|
|
144
148
|
return this.refreshAccessToken(isInitilization);
|
|
145
149
|
}
|
|
146
150
|
return accessToken;
|
|
147
151
|
}
|
|
148
152
|
isTokenExpired(token) {
|
|
149
153
|
const decoded = this.tokenToPayload(token);
|
|
150
|
-
|
|
154
|
+
const nowSeconds = Date.now() / 1e3;
|
|
155
|
+
return decoded.exp <= nowSeconds + this.tokenExpiryLeewaySeconds;
|
|
151
156
|
}
|
|
152
157
|
async mustBeLoggedIn() {
|
|
153
158
|
if (!await this.isLoggedIn()) {
|
|
@@ -168,6 +173,9 @@ var AuthManager = class _AuthManager {
|
|
|
168
173
|
}
|
|
169
174
|
if (this.isTokenExpired(accessToken)) {
|
|
170
175
|
try {
|
|
176
|
+
console.info(
|
|
177
|
+
"[AuthManager] Access token expired or near expiry; refreshing."
|
|
178
|
+
);
|
|
171
179
|
await this.refreshAccessToken();
|
|
172
180
|
return true;
|
|
173
181
|
} catch {
|