@redzone/taunt-logins 0.0.17 → 0.0.19

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.
@@ -351,6 +351,16 @@ const REFRESH_PATH = `/v1/auth/token/refresh`;
351
351
  const REFRESH_KEY = "taunt_refresh_token";
352
352
  const ACCESS_TOKEN_KEY = "taunt_access_token";
353
353
  class TauntApi {
354
+ optimisticSetAccessDetails() {
355
+ const accessToken = this.accessToken;
356
+ const refreshToken = this.refreshToken;
357
+ if (accessToken && this.setAccessDetails) {
358
+ this.setAccessDetails({
359
+ accessToken,
360
+ refreshToken: refreshToken ?? "__ignored__"
361
+ });
362
+ }
363
+ }
354
364
  get refreshToken() {
355
365
  return localStorage.getItem(REFRESH_KEY);
356
366
  }
@@ -393,6 +403,7 @@ class TauntApi {
393
403
  }
394
404
  if (data?.accessToken) {
395
405
  this.accessToken = data.accessToken;
406
+ this.optimisticSetAccessDetails();
396
407
  }
397
408
  return data;
398
409
  }
@@ -536,7 +547,8 @@ class TauntApi {
536
547
  });
537
548
  return Promise.resolve();
538
549
  }
539
- constructor(endpoint){
550
+ constructor(endpoint, setAccessDetails){
551
+ this.setAccessDetails = setAccessDetails;
540
552
  this.claimrToken = null;
541
553
  this.onError = async (error)=>{
542
554
  const originalRequest = error.config;
@@ -619,8 +631,8 @@ class TauntApi {
619
631
  baseURL: endpoint,
620
632
  withCredentials: true
621
633
  });
622
- // Response interceptor for API calls
623
634
  this._axios.interceptors.response.use((response)=>response, (error)=>this.onError(error));
635
+ this.optimisticSetAccessDetails();
624
636
  }
625
637
  }
626
638
 
@@ -249,13 +249,15 @@ interface AxiosErrorResponse {
249
249
  }>;
250
250
  }
251
251
  declare class TauntApi {
252
+ private setAccessDetails?;
252
253
  private _axios;
254
+ constructor(endpoint: string, setAccessDetails?: ((props: TauntAccessDetails) => void) | undefined);
255
+ private optimisticSetAccessDetails;
253
256
  get refreshToken(): string | null;
254
257
  set refreshToken(token: string | null);
255
258
  get accessToken(): string | null;
256
259
  set accessToken(token: string | null);
257
260
  private claimrToken;
258
- constructor(endpoint: string);
259
261
  onError: (error: AxiosErrorResponse) => Promise<AxiosResponse<any, any, {}>>;
260
262
  private _api;
261
263
  setLoginDetails: (props: TauntAccessDetails, checkGet?: boolean) => Promise<{
@@ -249,13 +249,15 @@ interface AxiosErrorResponse {
249
249
  }>;
250
250
  }
251
251
  declare class TauntApi {
252
+ private setAccessDetails?;
252
253
  private _axios;
254
+ constructor(endpoint: string, setAccessDetails?: ((props: TauntAccessDetails) => void) | undefined);
255
+ private optimisticSetAccessDetails;
253
256
  get refreshToken(): string | null;
254
257
  set refreshToken(token: string | null);
255
258
  get accessToken(): string | null;
256
259
  set accessToken(token: string | null);
257
260
  private claimrToken;
258
- constructor(endpoint: string);
259
261
  onError: (error: AxiosErrorResponse) => Promise<AxiosResponse<any, any, {}>>;
260
262
  private _api;
261
263
  setLoginDetails: (props: TauntAccessDetails, checkGet?: boolean) => Promise<{
package/dist/es/index.js CHANGED
@@ -345,6 +345,16 @@ const REFRESH_PATH = `/v1/auth/token/refresh`;
345
345
  const REFRESH_KEY = "taunt_refresh_token";
346
346
  const ACCESS_TOKEN_KEY = "taunt_access_token";
347
347
  class TauntApi {
348
+ optimisticSetAccessDetails() {
349
+ const accessToken = this.accessToken;
350
+ const refreshToken = this.refreshToken;
351
+ if (accessToken && this.setAccessDetails) {
352
+ this.setAccessDetails({
353
+ accessToken,
354
+ refreshToken: refreshToken ?? "__ignored__"
355
+ });
356
+ }
357
+ }
348
358
  get refreshToken() {
349
359
  return localStorage.getItem(REFRESH_KEY);
350
360
  }
@@ -387,6 +397,7 @@ class TauntApi {
387
397
  }
388
398
  if (data?.accessToken) {
389
399
  this.accessToken = data.accessToken;
400
+ this.optimisticSetAccessDetails();
390
401
  }
391
402
  return data;
392
403
  }
@@ -530,7 +541,8 @@ class TauntApi {
530
541
  });
531
542
  return Promise.resolve();
532
543
  }
533
- constructor(endpoint){
544
+ constructor(endpoint, setAccessDetails){
545
+ this.setAccessDetails = setAccessDetails;
534
546
  this.claimrToken = null;
535
547
  this.onError = async (error)=>{
536
548
  const originalRequest = error.config;
@@ -613,8 +625,8 @@ class TauntApi {
613
625
  baseURL: endpoint,
614
626
  withCredentials: true
615
627
  });
616
- // Response interceptor for API calls
617
628
  this._axios.interceptors.response.use((response)=>response, (error)=>this.onError(error));
629
+ this.optimisticSetAccessDetails();
618
630
  }
619
631
  }
620
632
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redzone/taunt-logins",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "files": [