zavadil-ts-common 1.1.70 → 1.1.71

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.
@@ -3,6 +3,7 @@ import {RestClient, RestClientHeaders} from "../client";
3
3
  import {IdTokenPayload} from "./OAuthRestClient";
4
4
  import {LazyAsync} from "../cache";
5
5
  import {DateUtil, StringUtil} from "../util";
6
+ import {JsonUtil} from "../util/JsonUtil";
6
7
 
7
8
  export type ServerOAuthInfoPayload = {
8
9
  debugMode?: boolean;
@@ -85,15 +86,8 @@ export class RestClientWithOAuth extends RestClient {
85
86
  return up.get('token');
86
87
  }
87
88
 
88
- getIdTokenFromLocalStorage(): IdTokenPayload | null {
89
- const raw = localStorage.getItem('id-token');
90
- if (!raw) return null;
91
- const obj = JSON.parse(raw);
92
- return {
93
- idToken: obj.idToken,
94
- issuedAt: DateUtil.parseDate(obj.issuedAt) || new Date(),
95
- expires: DateUtil.parseDate(obj.expires)
96
- }
89
+ getIdTokenFromLocalStorage(): IdTokenPayload | null | undefined {
90
+ return JsonUtil.parse(localStorage.getItem('id-token'));
97
91
  }
98
92
 
99
93
  saveIdTokenToLocalStorage(token: IdTokenPayload | null) {
@@ -13,4 +13,8 @@ export class JsonUtil {
13
13
  if (StringUtil.isBlank(json)) return undefined;
14
14
  return JSON.parse(StringUtil.getNonEmpty(json), JsonUtil.dateParser);
15
15
  }
16
+
17
+ static parse(json?: string | null): any {
18
+ return JsonUtil.parseWithDates(json);
19
+ }
16
20
  }