@etsoo/materialui 1.4.6 → 1.4.7

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.
@@ -1,4 +1,4 @@
1
- import { AppLoginParams, IAppSettings, IUser } from "@etsoo/appscript";
1
+ import { AppTryLoginParams, IAppSettings, IUser } from "@etsoo/appscript";
2
2
  import { IPageData } from "@etsoo/react";
3
3
  import { ReactApp } from "./ReactApp";
4
4
  /**
@@ -20,5 +20,5 @@ export declare abstract class CommonApp<U extends IUser = IUser, P extends IPage
20
20
  * @param showLoading Show loading bar or not
21
21
  * @returns Result
22
22
  */
23
- tryLogin(params?: AppLoginParams): Promise<void>;
23
+ tryLogin(params?: AppTryLoginParams): Promise<boolean>;
24
24
  }
@@ -27,18 +27,25 @@ export class CommonApp extends ReactApp {
27
27
  */
28
28
  async tryLogin(params) {
29
29
  // Check status
30
- if (this.isTryingLogin)
31
- return;
32
- this.isTryingLogin = true;
30
+ const result = await super.tryLogin(params);
31
+ if (!result) {
32
+ return false;
33
+ }
34
+ // Destruct
35
+ const { onFailure = () => {
36
+ this.toLoginPage(rest);
37
+ }, onSuccess, ...rest } = params ?? {};
33
38
  // Refresh token
34
39
  await this.refreshToken({
35
40
  showLoading: params?.showLoading
36
41
  }, (result) => {
37
- if (result) {
42
+ if (result === true) {
43
+ onSuccess?.();
38
44
  }
39
45
  else {
40
- this.toLoginPage(params);
46
+ onFailure();
41
47
  }
42
48
  });
49
+ return true;
43
50
  }
44
51
  }
@@ -1,4 +1,4 @@
1
- import { ApiRefreshTokenDto, AppLoginParams, ExternalEndpoint, IApi } from "@etsoo/appscript";
1
+ import { ApiRefreshTokenDto, AppLoginParams, AppTryLoginParams, ExternalEndpoint, IApi } from "@etsoo/appscript";
2
2
  import { IServiceApp } from "./IServiceApp";
3
3
  import { IServiceAppSettings } from "./IServiceAppSettings";
4
4
  import { IServicePageData } from "./IServicePage";
@@ -54,4 +54,9 @@ export declare class ServiceApp<U extends IServiceUser = IServiceUser, P extends
54
54
  * @param dispatch User state dispatch
55
55
  */
56
56
  userLoginEx(user: U & ServiceUserToken, core?: ApiRefreshTokenDto, dispatch?: boolean): void;
57
+ /**
58
+ * Try login
59
+ * @param params Login parameters
60
+ */
61
+ tryLogin(params?: AppTryLoginParams): Promise<boolean>;
57
62
  }
@@ -113,4 +113,26 @@ export class ServiceApp extends ReactApp {
113
113
  this.storage.setData(coreTokenKey, core.refreshToken);
114
114
  this.exchangeTokenAll(core, coreName);
115
115
  }
116
+ /**
117
+ * Try login
118
+ * @param params Login parameters
119
+ */
120
+ async tryLogin(params) {
121
+ // Check core system token
122
+ const coreToken = this.storage.getData(coreTokenKey);
123
+ if (!coreToken)
124
+ return false;
125
+ params ?? (params = {});
126
+ const onSuccess = params.onSuccess;
127
+ params.onSuccess = () => {
128
+ // Call the core system API refresh token
129
+ this.apiRefreshTokenData(this.coreApi, coreToken).then((data) => {
130
+ if (data == null)
131
+ return;
132
+ this.exchangeTokenAll(data, coreName);
133
+ onSuccess?.();
134
+ });
135
+ };
136
+ return await super.tryLogin(params);
137
+ }
116
138
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.4.6",
3
+ "version": "1.4.7",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -50,9 +50,9 @@
50
50
  "@emotion/css": "^11.13.4",
51
51
  "@emotion/react": "^11.13.3",
52
52
  "@emotion/styled": "^11.13.0",
53
- "@etsoo/appscript": "^1.5.47",
53
+ "@etsoo/appscript": "^1.5.49",
54
54
  "@etsoo/notificationbase": "^1.1.49",
55
- "@etsoo/react": "^1.7.80",
55
+ "@etsoo/react": "^1.7.82",
56
56
  "@etsoo/shared": "^1.2.48",
57
57
  "@mui/icons-material": "^6.1.4",
58
58
  "@mui/material": "^6.1.4",
@@ -1,4 +1,4 @@
1
- import { AppLoginParams, IAppSettings, IUser } from "@etsoo/appscript";
1
+ import { AppTryLoginParams, IAppSettings, IUser } from "@etsoo/appscript";
2
2
  import { CoreConstants, IPageData } from "@etsoo/react";
3
3
  import { ReactApp } from "./ReactApp";
4
4
 
@@ -33,10 +33,21 @@ export abstract class CommonApp<
33
33
  * @param showLoading Show loading bar or not
34
34
  * @returns Result
35
35
  */
36
- override async tryLogin(params?: AppLoginParams) {
36
+ override async tryLogin(params?: AppTryLoginParams) {
37
37
  // Check status
38
- if (this.isTryingLogin) return;
39
- this.isTryingLogin = true;
38
+ const result = await super.tryLogin(params);
39
+ if (!result) {
40
+ return false;
41
+ }
42
+
43
+ // Destruct
44
+ const {
45
+ onFailure = () => {
46
+ this.toLoginPage(rest);
47
+ },
48
+ onSuccess,
49
+ ...rest
50
+ } = params ?? {};
40
51
 
41
52
  // Refresh token
42
53
  await this.refreshToken(
@@ -44,11 +55,14 @@ export abstract class CommonApp<
44
55
  showLoading: params?.showLoading
45
56
  },
46
57
  (result) => {
47
- if (result) {
58
+ if (result === true) {
59
+ onSuccess?.();
48
60
  } else {
49
- this.toLoginPage(params);
61
+ onFailure();
50
62
  }
51
63
  }
52
64
  );
65
+
66
+ return true;
53
67
  }
54
68
  }
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  ApiRefreshTokenDto,
3
3
  AppLoginParams,
4
+ AppTryLoginParams,
4
5
  AuthApi,
5
6
  BridgeUtils,
6
7
  ExternalEndpoint,
@@ -165,4 +166,28 @@ export class ServiceApp<
165
166
 
166
167
  this.exchangeTokenAll(core, coreName);
167
168
  }
169
+
170
+ /**
171
+ * Try login
172
+ * @param params Login parameters
173
+ */
174
+ override async tryLogin(params?: AppTryLoginParams) {
175
+ // Check core system token
176
+ const coreToken = this.storage.getData<string>(coreTokenKey);
177
+ if (!coreToken) return false;
178
+
179
+ params ??= {};
180
+ const onSuccess = params.onSuccess;
181
+ params.onSuccess = () => {
182
+ // Call the core system API refresh token
183
+ this.apiRefreshTokenData(this.coreApi, coreToken).then((data) => {
184
+ if (data == null) return;
185
+
186
+ this.exchangeTokenAll(data, coreName);
187
+
188
+ onSuccess?.();
189
+ });
190
+ };
191
+ return await super.tryLogin(params);
192
+ }
168
193
  }