@etsoo/materialui 1.4.60 → 1.4.61

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.
@@ -233,7 +233,8 @@ export class ReactApp extends CoreApp {
233
233
  */
234
234
  async tryLogin(data) {
235
235
  // Destruct
236
- const { onFailure = () => {
236
+ const { onFailure = (type) => {
237
+ console.log(`Try login failed: ${type}.`);
237
238
  this.toLoginPage(rest);
238
239
  }, onSuccess, ...rest } = data ?? {};
239
240
  // Check status
@@ -67,6 +67,7 @@ export declare class ServiceApp<U extends IServiceUser = IServiceUser, P extends
67
67
  * @param payload Payload
68
68
  */
69
69
  switchOrg(organizationId: number, fromOrganizationId?: number, payload?: IApiPayload<IActionResult<U & ServiceUserToken>>): Promise<IActionResult<U & ServiceUserToken> | undefined>;
70
+ protected refreshTokenSucceed(user: U, token: string, callback?: (result?: boolean | IActionResult) => boolean | void): Promise<void>;
70
71
  /**
71
72
  * Try login
72
73
  * @param params Login parameters
@@ -180,6 +180,35 @@ export class ServiceApp extends ReactApp {
180
180
  this.userLoginEx(user, core, true);
181
181
  return result;
182
182
  }
183
+ async refreshTokenSucceed(user, token, callback) {
184
+ // Check core system token
185
+ const coreToken = this.storage.getData(coreTokenKey);
186
+ if (!coreToken) {
187
+ callback?.({ ok: false, type: "noData", title: "Core token is blank" });
188
+ return;
189
+ }
190
+ const coreTokenDecrypted = this.decrypt(coreToken);
191
+ if (!coreTokenDecrypted) {
192
+ callback?.({
193
+ ok: false,
194
+ type: "noData",
195
+ title: "Core token decrypted is blank"
196
+ });
197
+ return;
198
+ }
199
+ // Call the core system API refresh token
200
+ const data = await this.apiRefreshTokenData(this.coreApi, {
201
+ token: coreTokenDecrypted,
202
+ appId: this.settings.appId
203
+ });
204
+ if (data == null)
205
+ return;
206
+ // Cache the core system refresh token
207
+ // Follow similar logic in userLoginEx
208
+ this.saveCoreToken(data);
209
+ // Call the super
210
+ await super.refreshTokenSucceed(user, token, callback);
211
+ }
183
212
  /**
184
213
  * Try login
185
214
  * @param params Login parameters
@@ -187,37 +216,13 @@ export class ServiceApp extends ReactApp {
187
216
  async tryLogin(params) {
188
217
  // Destruct
189
218
  params ??= {};
190
- let { onFailure, onSuccess, ...rest } = params;
219
+ let { onFailure, ...rest } = params;
191
220
  if (onFailure == null) {
192
221
  onFailure = params.onFailure = (type) => {
193
222
  console.log(`Try login failed: ${type}.`);
194
223
  this.toLoginPage(rest);
195
224
  };
196
225
  }
197
- // Check core system token
198
- const coreToken = this.storage.getData(coreTokenKey);
199
- if (!coreToken) {
200
- onFailure("ServiceAppCoreTokenNoData");
201
- return false;
202
- }
203
- const coreTokenDecrypted = this.decrypt(coreToken);
204
- if (!coreTokenDecrypted) {
205
- onFailure("ServiceAppCoreTokenNoDecryptedData");
206
- return false;
207
- }
208
- params.onSuccess = () => {
209
- // Call the core system API refresh token
210
- this.apiRefreshTokenData(this.coreApi, {
211
- token: coreTokenDecrypted,
212
- appId: this.settings.appId
213
- }).then((data) => {
214
- if (data == null)
215
- return;
216
- // Cache the core system refresh token
217
- this.saveCoreToken(data);
218
- onSuccess?.();
219
- });
220
- };
221
226
  return await super.tryLogin(params);
222
227
  }
223
228
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.4.60",
3
+ "version": "1.4.61",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
@@ -35,9 +35,9 @@
35
35
  "@emotion/css": "^11.13.5",
36
36
  "@emotion/react": "^11.14.0",
37
37
  "@emotion/styled": "^11.14.0",
38
- "@etsoo/appscript": "^1.5.84",
38
+ "@etsoo/appscript": "^1.5.87",
39
39
  "@etsoo/notificationbase": "^1.1.54",
40
- "@etsoo/react": "^1.8.17",
40
+ "@etsoo/react": "^1.8.20",
41
41
  "@etsoo/shared": "^1.2.55",
42
42
  "@mui/icons-material": "^6.3.1",
43
43
  "@mui/material": "^6.3.1",
@@ -72,7 +72,7 @@
72
72
  "@types/react-window": "^1.8.8",
73
73
  "@vitejs/plugin-react": "^4.3.4",
74
74
  "jsdom": "^25.0.1",
75
- "typescript": "^5.7.2",
75
+ "typescript": "^5.7.3",
76
76
  "vitest": "^2.1.8"
77
77
  }
78
78
  }
@@ -427,7 +427,8 @@ export class ReactApp<
427
427
  override async tryLogin(data?: AppTryLoginParams) {
428
428
  // Destruct
429
429
  const {
430
- onFailure = () => {
430
+ onFailure = (type: string) => {
431
+ console.log(`Try login failed: ${type}.`);
431
432
  this.toLoginPage(rest);
432
433
  },
433
434
  onSuccess,
@@ -244,6 +244,44 @@ export class ServiceApp<
244
244
  return result;
245
245
  }
246
246
 
247
+ protected override async refreshTokenSucceed(
248
+ user: U,
249
+ token: string,
250
+ callback?: (result?: boolean | IActionResult) => boolean | void
251
+ ): Promise<void> {
252
+ // Check core system token
253
+ const coreToken = this.storage.getData<string>(coreTokenKey);
254
+ if (!coreToken) {
255
+ callback?.({ ok: false, type: "noData", title: "Core token is blank" });
256
+ return;
257
+ }
258
+
259
+ const coreTokenDecrypted = this.decrypt(coreToken);
260
+ if (!coreTokenDecrypted) {
261
+ callback?.({
262
+ ok: false,
263
+ type: "noData",
264
+ title: "Core token decrypted is blank"
265
+ });
266
+ return;
267
+ }
268
+
269
+ // Call the core system API refresh token
270
+ const data = await this.apiRefreshTokenData(this.coreApi, {
271
+ token: coreTokenDecrypted,
272
+ appId: this.settings.appId
273
+ });
274
+
275
+ if (data == null) return;
276
+
277
+ // Cache the core system refresh token
278
+ // Follow similar logic in userLoginEx
279
+ this.saveCoreToken(data);
280
+
281
+ // Call the super
282
+ await super.refreshTokenSucceed(user, token, callback);
283
+ }
284
+
247
285
  /**
248
286
  * Try login
249
287
  * @param params Login parameters
@@ -251,7 +289,7 @@ export class ServiceApp<
251
289
  override async tryLogin(params?: AppTryLoginParams) {
252
290
  // Destruct
253
291
  params ??= {};
254
- let { onFailure, onSuccess, ...rest } = params;
292
+ let { onFailure, ...rest } = params;
255
293
 
256
294
  if (onFailure == null) {
257
295
  onFailure = params.onFailure = (type) => {
@@ -260,34 +298,6 @@ export class ServiceApp<
260
298
  };
261
299
  }
262
300
 
263
- // Check core system token
264
- const coreToken = this.storage.getData<string>(coreTokenKey);
265
- if (!coreToken) {
266
- onFailure("ServiceAppCoreTokenNoData");
267
- return false;
268
- }
269
-
270
- const coreTokenDecrypted = this.decrypt(coreToken);
271
- if (!coreTokenDecrypted) {
272
- onFailure("ServiceAppCoreTokenNoDecryptedData");
273
- return false;
274
- }
275
-
276
- params.onSuccess = () => {
277
- // Call the core system API refresh token
278
- this.apiRefreshTokenData(this.coreApi, {
279
- token: coreTokenDecrypted,
280
- appId: this.settings.appId
281
- }).then((data) => {
282
- if (data == null) return;
283
-
284
- // Cache the core system refresh token
285
- this.saveCoreToken(data);
286
-
287
- onSuccess?.();
288
- });
289
- };
290
-
291
301
  return await super.tryLogin(params);
292
302
  }
293
303
  }