@redzone/taunt-logins 0.0.16 → 0.0.17
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.cjs +20 -1
- package/dist/cjs/index.d.cts +2 -0
- package/dist/es/index.d.ts +2 -0
- package/dist/es/index.js +20 -1
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -347,7 +347,9 @@ function ErrorFromResponse(response) {
|
|
|
347
347
|
}
|
|
348
348
|
}
|
|
349
349
|
|
|
350
|
+
const REFRESH_PATH = `/v1/auth/token/refresh`;
|
|
350
351
|
const REFRESH_KEY = "taunt_refresh_token";
|
|
352
|
+
const ACCESS_TOKEN_KEY = "taunt_access_token";
|
|
351
353
|
class TauntApi {
|
|
352
354
|
get refreshToken() {
|
|
353
355
|
return localStorage.getItem(REFRESH_KEY);
|
|
@@ -359,7 +361,20 @@ class TauntApi {
|
|
|
359
361
|
localStorage.removeItem(REFRESH_KEY);
|
|
360
362
|
}
|
|
361
363
|
}
|
|
364
|
+
get accessToken() {
|
|
365
|
+
return localStorage.getItem(ACCESS_TOKEN_KEY);
|
|
366
|
+
}
|
|
367
|
+
set accessToken(token) {
|
|
368
|
+
if (token) {
|
|
369
|
+
localStorage.setItem(ACCESS_TOKEN_KEY, token);
|
|
370
|
+
} else {
|
|
371
|
+
localStorage.removeItem(ACCESS_TOKEN_KEY);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
362
374
|
async _api(method, url, body, headers = {}) {
|
|
375
|
+
if (url !== REFRESH_PATH && !this.accessToken && this.refreshToken) {
|
|
376
|
+
await this.refresh();
|
|
377
|
+
}
|
|
363
378
|
headers = {
|
|
364
379
|
"Content-Type": "application/json",
|
|
365
380
|
Accept: "application/json",
|
|
@@ -376,6 +391,9 @@ class TauntApi {
|
|
|
376
391
|
if (data?.refreshToken) {
|
|
377
392
|
this.refreshToken = data.refreshToken;
|
|
378
393
|
}
|
|
394
|
+
if (data?.accessToken) {
|
|
395
|
+
this.accessToken = data.accessToken;
|
|
396
|
+
}
|
|
379
397
|
return data;
|
|
380
398
|
}
|
|
381
399
|
async post(url, body = {}, headers = {}) {
|
|
@@ -531,6 +549,7 @@ class TauntApi {
|
|
|
531
549
|
} catch (error) {
|
|
532
550
|
console.log("Unable to refresh access token, please log in");
|
|
533
551
|
this.refreshToken = null;
|
|
552
|
+
this.accessToken = null;
|
|
534
553
|
// window.location.href = "/"
|
|
535
554
|
return Promise.reject(error);
|
|
536
555
|
}
|
|
@@ -566,7 +585,7 @@ class TauntApi {
|
|
|
566
585
|
if (!token) {
|
|
567
586
|
return Promise.reject(new Error("No refresh token available"));
|
|
568
587
|
}
|
|
569
|
-
return this.post(
|
|
588
|
+
return this.post(REFRESH_PATH, {
|
|
570
589
|
token
|
|
571
590
|
});
|
|
572
591
|
};
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -252,6 +252,8 @@ declare class TauntApi {
|
|
|
252
252
|
private _axios;
|
|
253
253
|
get refreshToken(): string | null;
|
|
254
254
|
set refreshToken(token: string | null);
|
|
255
|
+
get accessToken(): string | null;
|
|
256
|
+
set accessToken(token: string | null);
|
|
255
257
|
private claimrToken;
|
|
256
258
|
constructor(endpoint: string);
|
|
257
259
|
onError: (error: AxiosErrorResponse) => Promise<AxiosResponse<any, any, {}>>;
|
package/dist/es/index.d.ts
CHANGED
|
@@ -252,6 +252,8 @@ declare class TauntApi {
|
|
|
252
252
|
private _axios;
|
|
253
253
|
get refreshToken(): string | null;
|
|
254
254
|
set refreshToken(token: string | null);
|
|
255
|
+
get accessToken(): string | null;
|
|
256
|
+
set accessToken(token: string | null);
|
|
255
257
|
private claimrToken;
|
|
256
258
|
constructor(endpoint: string);
|
|
257
259
|
onError: (error: AxiosErrorResponse) => Promise<AxiosResponse<any, any, {}>>;
|
package/dist/es/index.js
CHANGED
|
@@ -341,7 +341,9 @@ function ErrorFromResponse(response) {
|
|
|
341
341
|
}
|
|
342
342
|
}
|
|
343
343
|
|
|
344
|
+
const REFRESH_PATH = `/v1/auth/token/refresh`;
|
|
344
345
|
const REFRESH_KEY = "taunt_refresh_token";
|
|
346
|
+
const ACCESS_TOKEN_KEY = "taunt_access_token";
|
|
345
347
|
class TauntApi {
|
|
346
348
|
get refreshToken() {
|
|
347
349
|
return localStorage.getItem(REFRESH_KEY);
|
|
@@ -353,7 +355,20 @@ class TauntApi {
|
|
|
353
355
|
localStorage.removeItem(REFRESH_KEY);
|
|
354
356
|
}
|
|
355
357
|
}
|
|
358
|
+
get accessToken() {
|
|
359
|
+
return localStorage.getItem(ACCESS_TOKEN_KEY);
|
|
360
|
+
}
|
|
361
|
+
set accessToken(token) {
|
|
362
|
+
if (token) {
|
|
363
|
+
localStorage.setItem(ACCESS_TOKEN_KEY, token);
|
|
364
|
+
} else {
|
|
365
|
+
localStorage.removeItem(ACCESS_TOKEN_KEY);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
356
368
|
async _api(method, url, body, headers = {}) {
|
|
369
|
+
if (url !== REFRESH_PATH && !this.accessToken && this.refreshToken) {
|
|
370
|
+
await this.refresh();
|
|
371
|
+
}
|
|
357
372
|
headers = {
|
|
358
373
|
"Content-Type": "application/json",
|
|
359
374
|
Accept: "application/json",
|
|
@@ -370,6 +385,9 @@ class TauntApi {
|
|
|
370
385
|
if (data?.refreshToken) {
|
|
371
386
|
this.refreshToken = data.refreshToken;
|
|
372
387
|
}
|
|
388
|
+
if (data?.accessToken) {
|
|
389
|
+
this.accessToken = data.accessToken;
|
|
390
|
+
}
|
|
373
391
|
return data;
|
|
374
392
|
}
|
|
375
393
|
async post(url, body = {}, headers = {}) {
|
|
@@ -525,6 +543,7 @@ class TauntApi {
|
|
|
525
543
|
} catch (error) {
|
|
526
544
|
console.log("Unable to refresh access token, please log in");
|
|
527
545
|
this.refreshToken = null;
|
|
546
|
+
this.accessToken = null;
|
|
528
547
|
// window.location.href = "/"
|
|
529
548
|
return Promise.reject(error);
|
|
530
549
|
}
|
|
@@ -560,7 +579,7 @@ class TauntApi {
|
|
|
560
579
|
if (!token) {
|
|
561
580
|
return Promise.reject(new Error("No refresh token available"));
|
|
562
581
|
}
|
|
563
|
-
return this.post(
|
|
582
|
+
return this.post(REFRESH_PATH, {
|
|
564
583
|
token
|
|
565
584
|
});
|
|
566
585
|
};
|