@redzone/taunt-logins 0.0.18 → 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,10 +403,7 @@ class TauntApi {
393
403
  }
394
404
  if (data?.accessToken) {
395
405
  this.accessToken = data.accessToken;
396
- this.setAccessDetails?.({
397
- accessToken: data.accessToken,
398
- refreshToken: data.refreshToken ?? "_ignore_"
399
- });
406
+ this.optimisticSetAccessDetails();
400
407
  }
401
408
  return data;
402
409
  }
@@ -625,6 +632,7 @@ class TauntApi {
625
632
  withCredentials: true
626
633
  });
627
634
  this._axios.interceptors.response.use((response)=>response, (error)=>this.onError(error));
635
+ this.optimisticSetAccessDetails();
628
636
  }
629
637
  }
630
638
 
@@ -252,6 +252,7 @@ declare class TauntApi {
252
252
  private setAccessDetails?;
253
253
  private _axios;
254
254
  constructor(endpoint: string, setAccessDetails?: ((props: TauntAccessDetails) => void) | undefined);
255
+ private optimisticSetAccessDetails;
255
256
  get refreshToken(): string | null;
256
257
  set refreshToken(token: string | null);
257
258
  get accessToken(): string | null;
@@ -252,6 +252,7 @@ declare class TauntApi {
252
252
  private setAccessDetails?;
253
253
  private _axios;
254
254
  constructor(endpoint: string, setAccessDetails?: ((props: TauntAccessDetails) => void) | undefined);
255
+ private optimisticSetAccessDetails;
255
256
  get refreshToken(): string | null;
256
257
  set refreshToken(token: string | null);
257
258
  get accessToken(): string | null;
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,10 +397,7 @@ class TauntApi {
387
397
  }
388
398
  if (data?.accessToken) {
389
399
  this.accessToken = data.accessToken;
390
- this.setAccessDetails?.({
391
- accessToken: data.accessToken,
392
- refreshToken: data.refreshToken ?? "_ignore_"
393
- });
400
+ this.optimisticSetAccessDetails();
394
401
  }
395
402
  return data;
396
403
  }
@@ -619,6 +626,7 @@ class TauntApi {
619
626
  withCredentials: true
620
627
  });
621
628
  this._axios.interceptors.response.use((response)=>response, (error)=>this.onError(error));
629
+ this.optimisticSetAccessDetails();
622
630
  }
623
631
  }
624
632
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redzone/taunt-logins",
3
- "version": "0.0.18",
3
+ "version": "0.0.19",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "files": [