@redzone/taunt-logins 0.0.15 → 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 +31 -3
- package/dist/cjs/index.d.cts +4 -1
- package/dist/es/index.d.ts +4 -1
- package/dist/es/index.js +31 -3
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -347,8 +347,34 @@ function ErrorFromResponse(response) {
|
|
|
347
347
|
}
|
|
348
348
|
}
|
|
349
349
|
|
|
350
|
+
const REFRESH_PATH = `/v1/auth/token/refresh`;
|
|
351
|
+
const REFRESH_KEY = "taunt_refresh_token";
|
|
352
|
+
const ACCESS_TOKEN_KEY = "taunt_access_token";
|
|
350
353
|
class TauntApi {
|
|
354
|
+
get refreshToken() {
|
|
355
|
+
return localStorage.getItem(REFRESH_KEY);
|
|
356
|
+
}
|
|
357
|
+
set refreshToken(token) {
|
|
358
|
+
if (token) {
|
|
359
|
+
localStorage.setItem(REFRESH_KEY, token);
|
|
360
|
+
} else {
|
|
361
|
+
localStorage.removeItem(REFRESH_KEY);
|
|
362
|
+
}
|
|
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
|
+
}
|
|
351
374
|
async _api(method, url, body, headers = {}) {
|
|
375
|
+
if (url !== REFRESH_PATH && !this.accessToken && this.refreshToken) {
|
|
376
|
+
await this.refresh();
|
|
377
|
+
}
|
|
352
378
|
headers = {
|
|
353
379
|
"Content-Type": "application/json",
|
|
354
380
|
Accept: "application/json",
|
|
@@ -365,6 +391,9 @@ class TauntApi {
|
|
|
365
391
|
if (data?.refreshToken) {
|
|
366
392
|
this.refreshToken = data.refreshToken;
|
|
367
393
|
}
|
|
394
|
+
if (data?.accessToken) {
|
|
395
|
+
this.accessToken = data.accessToken;
|
|
396
|
+
}
|
|
368
397
|
return data;
|
|
369
398
|
}
|
|
370
399
|
async post(url, body = {}, headers = {}) {
|
|
@@ -389,7 +418,6 @@ class TauntApi {
|
|
|
389
418
|
try {
|
|
390
419
|
signature = await provider.personalSign(message, walletAddress);
|
|
391
420
|
} catch (err) {
|
|
392
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
393
421
|
throw new Error(`User denied message signature, ${err}`);
|
|
394
422
|
}
|
|
395
423
|
if (!signature) {
|
|
@@ -509,7 +537,6 @@ class TauntApi {
|
|
|
509
537
|
return Promise.resolve();
|
|
510
538
|
}
|
|
511
539
|
constructor(endpoint){
|
|
512
|
-
this.refreshToken = null;
|
|
513
540
|
this.claimrToken = null;
|
|
514
541
|
this.onError = async (error)=>{
|
|
515
542
|
const originalRequest = error.config;
|
|
@@ -522,6 +549,7 @@ class TauntApi {
|
|
|
522
549
|
} catch (error) {
|
|
523
550
|
console.log("Unable to refresh access token, please log in");
|
|
524
551
|
this.refreshToken = null;
|
|
552
|
+
this.accessToken = null;
|
|
525
553
|
// window.location.href = "/"
|
|
526
554
|
return Promise.reject(error);
|
|
527
555
|
}
|
|
@@ -557,7 +585,7 @@ class TauntApi {
|
|
|
557
585
|
if (!token) {
|
|
558
586
|
return Promise.reject(new Error("No refresh token available"));
|
|
559
587
|
}
|
|
560
|
-
return this.post(
|
|
588
|
+
return this.post(REFRESH_PATH, {
|
|
561
589
|
token
|
|
562
590
|
});
|
|
563
591
|
};
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -250,7 +250,10 @@ interface AxiosErrorResponse {
|
|
|
250
250
|
}
|
|
251
251
|
declare class TauntApi {
|
|
252
252
|
private _axios;
|
|
253
|
-
|
|
253
|
+
get refreshToken(): string | null;
|
|
254
|
+
set refreshToken(token: string | null);
|
|
255
|
+
get accessToken(): string | null;
|
|
256
|
+
set accessToken(token: string | null);
|
|
254
257
|
private claimrToken;
|
|
255
258
|
constructor(endpoint: string);
|
|
256
259
|
onError: (error: AxiosErrorResponse) => Promise<AxiosResponse<any, any, {}>>;
|
package/dist/es/index.d.ts
CHANGED
|
@@ -250,7 +250,10 @@ interface AxiosErrorResponse {
|
|
|
250
250
|
}
|
|
251
251
|
declare class TauntApi {
|
|
252
252
|
private _axios;
|
|
253
|
-
|
|
253
|
+
get refreshToken(): string | null;
|
|
254
|
+
set refreshToken(token: string | null);
|
|
255
|
+
get accessToken(): string | null;
|
|
256
|
+
set accessToken(token: string | null);
|
|
254
257
|
private claimrToken;
|
|
255
258
|
constructor(endpoint: string);
|
|
256
259
|
onError: (error: AxiosErrorResponse) => Promise<AxiosResponse<any, any, {}>>;
|
package/dist/es/index.js
CHANGED
|
@@ -341,8 +341,34 @@ function ErrorFromResponse(response) {
|
|
|
341
341
|
}
|
|
342
342
|
}
|
|
343
343
|
|
|
344
|
+
const REFRESH_PATH = `/v1/auth/token/refresh`;
|
|
345
|
+
const REFRESH_KEY = "taunt_refresh_token";
|
|
346
|
+
const ACCESS_TOKEN_KEY = "taunt_access_token";
|
|
344
347
|
class TauntApi {
|
|
348
|
+
get refreshToken() {
|
|
349
|
+
return localStorage.getItem(REFRESH_KEY);
|
|
350
|
+
}
|
|
351
|
+
set refreshToken(token) {
|
|
352
|
+
if (token) {
|
|
353
|
+
localStorage.setItem(REFRESH_KEY, token);
|
|
354
|
+
} else {
|
|
355
|
+
localStorage.removeItem(REFRESH_KEY);
|
|
356
|
+
}
|
|
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
|
+
}
|
|
345
368
|
async _api(method, url, body, headers = {}) {
|
|
369
|
+
if (url !== REFRESH_PATH && !this.accessToken && this.refreshToken) {
|
|
370
|
+
await this.refresh();
|
|
371
|
+
}
|
|
346
372
|
headers = {
|
|
347
373
|
"Content-Type": "application/json",
|
|
348
374
|
Accept: "application/json",
|
|
@@ -359,6 +385,9 @@ class TauntApi {
|
|
|
359
385
|
if (data?.refreshToken) {
|
|
360
386
|
this.refreshToken = data.refreshToken;
|
|
361
387
|
}
|
|
388
|
+
if (data?.accessToken) {
|
|
389
|
+
this.accessToken = data.accessToken;
|
|
390
|
+
}
|
|
362
391
|
return data;
|
|
363
392
|
}
|
|
364
393
|
async post(url, body = {}, headers = {}) {
|
|
@@ -383,7 +412,6 @@ class TauntApi {
|
|
|
383
412
|
try {
|
|
384
413
|
signature = await provider.personalSign(message, walletAddress);
|
|
385
414
|
} catch (err) {
|
|
386
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
387
415
|
throw new Error(`User denied message signature, ${err}`);
|
|
388
416
|
}
|
|
389
417
|
if (!signature) {
|
|
@@ -503,7 +531,6 @@ class TauntApi {
|
|
|
503
531
|
return Promise.resolve();
|
|
504
532
|
}
|
|
505
533
|
constructor(endpoint){
|
|
506
|
-
this.refreshToken = null;
|
|
507
534
|
this.claimrToken = null;
|
|
508
535
|
this.onError = async (error)=>{
|
|
509
536
|
const originalRequest = error.config;
|
|
@@ -516,6 +543,7 @@ class TauntApi {
|
|
|
516
543
|
} catch (error) {
|
|
517
544
|
console.log("Unable to refresh access token, please log in");
|
|
518
545
|
this.refreshToken = null;
|
|
546
|
+
this.accessToken = null;
|
|
519
547
|
// window.location.href = "/"
|
|
520
548
|
return Promise.reject(error);
|
|
521
549
|
}
|
|
@@ -551,7 +579,7 @@ class TauntApi {
|
|
|
551
579
|
if (!token) {
|
|
552
580
|
return Promise.reject(new Error("No refresh token available"));
|
|
553
581
|
}
|
|
554
|
-
return this.post(
|
|
582
|
+
return this.post(REFRESH_PATH, {
|
|
555
583
|
token
|
|
556
584
|
});
|
|
557
585
|
};
|