@arcblock/did-connect-react 3.4.14 → 3.5.0

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.
Files changed (208) hide show
  1. package/dist/standalone/did-connect-react.css +1 -0
  2. package/dist/standalone/index.js +133700 -0
  3. package/lib/Connect/components/login-item/connect-choose-list.js +111 -111
  4. package/lib/Connect/components/login-item/connect-provider-list.js +180 -180
  5. package/lib/Connect/components/login-item/mobile-login-item.js +56 -56
  6. package/lib/Connect/components/login-item/passkey-login-item.js +27 -29
  7. package/lib/Connect/components/login-item/web-login-item.js +31 -29
  8. package/lib/Connect/connect.js +202 -197
  9. package/lib/Connect/contexts/state.js +19 -17
  10. package/lib/Connect/hooks/provider-list.js +33 -33
  11. package/lib/Connect/plugins/email/list-item.js +14 -14
  12. package/lib/Connect/plugins/email/placeholder.js +77 -76
  13. package/lib/package.json.js +1 -1
  14. package/package.json +14 -9
  15. package/.aigne/doc-smith/config.yaml +0 -85
  16. package/.aigne/doc-smith/history.yaml +0 -6
  17. package/.aigne/doc-smith/output/structure-plan.json +0 -204
  18. package/.aigne/doc-smith/translation-cache.yaml +0 -11
  19. package/.aigne/doc-smith/upload-cache.yaml +0 -213
  20. package/docs/_sidebar.md +0 -18
  21. package/docs/advanced-authentication-methods.ja.md +0 -261
  22. package/docs/advanced-authentication-methods.md +0 -261
  23. package/docs/advanced-authentication-methods.zh-TW.md +0 -261
  24. package/docs/advanced-authentication-methods.zh.md +0 -261
  25. package/docs/advanced-utilities.ja.md +0 -132
  26. package/docs/advanced-utilities.md +0 -132
  27. package/docs/advanced-utilities.zh-TW.md +0 -132
  28. package/docs/advanced-utilities.zh.md +0 -132
  29. package/docs/advanced.ja.md +0 -95
  30. package/docs/advanced.md +0 -95
  31. package/docs/advanced.zh-TW.md +0 -95
  32. package/docs/advanced.zh.md +0 -95
  33. package/docs/api-reference.ja.md +0 -178
  34. package/docs/api-reference.md +0 -178
  35. package/docs/api-reference.zh-TW.md +0 -178
  36. package/docs/api-reference.zh.md +0 -178
  37. package/docs/assets/diagram/core-components-session-provider-01.ja.jpg +0 -0
  38. package/docs/assets/diagram/core-components-session-provider-01.jpg +0 -0
  39. package/docs/assets/diagram/core-components-session-provider-01.zh-TW.jpg +0 -0
  40. package/docs/assets/diagram/core-components-session-provider-01.zh.jpg +0 -0
  41. package/docs/assets/diagram/did-connect-diagram-0.ja.jpg +0 -0
  42. package/docs/assets/diagram/did-connect-diagram-0.jpg +0 -0
  43. package/docs/assets/diagram/did-connect-diagram-0.zh-TW.jpg +0 -0
  44. package/docs/assets/diagram/did-connect-diagram-0.zh.jpg +0 -0
  45. package/docs/assets/diagram/overview-01.ja.jpg +0 -0
  46. package/docs/assets/diagram/overview-01.jpg +0 -0
  47. package/docs/assets/diagram/overview-01.zh-TW.jpg +0 -0
  48. package/docs/assets/diagram/overview-01.zh.jpg +0 -0
  49. package/docs/assets/diagram/use-connect-diagram-0.ja.jpg +0 -0
  50. package/docs/assets/diagram/use-connect-diagram-0.jpg +0 -0
  51. package/docs/assets/diagram/use-connect-diagram-0.zh-TW.jpg +0 -0
  52. package/docs/assets/diagram/use-connect-diagram-0.zh.jpg +0 -0
  53. package/docs/core-components-did-connect.ja.md +0 -166
  54. package/docs/core-components-did-connect.md +0 -166
  55. package/docs/core-components-did-connect.zh-TW.md +0 -166
  56. package/docs/core-components-did-connect.zh.md +0 -166
  57. package/docs/core-components-session-provider.ja.md +0 -197
  58. package/docs/core-components-session-provider.md +0 -197
  59. package/docs/core-components-session-provider.zh-TW.md +0 -197
  60. package/docs/core-components-session-provider.zh.md +0 -197
  61. package/docs/core-components.ja.md +0 -16
  62. package/docs/core-components.md +0 -16
  63. package/docs/core-components.zh-TW.md +0 -16
  64. package/docs/core-components.zh.md +0 -16
  65. package/docs/getting-started.ja.md +0 -138
  66. package/docs/getting-started.md +0 -138
  67. package/docs/getting-started.zh-TW.md +0 -138
  68. package/docs/getting-started.zh.md +0 -138
  69. package/docs/hooks-use-connect.ja.md +0 -178
  70. package/docs/hooks-use-connect.md +0 -178
  71. package/docs/hooks-use-connect.zh-TW.md +0 -178
  72. package/docs/hooks-use-connect.zh.md +0 -178
  73. package/docs/hooks-use-did.ja.md +0 -107
  74. package/docs/hooks-use-did.md +0 -107
  75. package/docs/hooks-use-did.zh-TW.md +0 -107
  76. package/docs/hooks-use-did.zh.md +0 -107
  77. package/docs/hooks-use-oauth-passkey.ja.md +0 -188
  78. package/docs/hooks-use-oauth-passkey.md +0 -188
  79. package/docs/hooks-use-oauth-passkey.zh-TW.md +0 -188
  80. package/docs/hooks-use-oauth-passkey.zh.md +0 -188
  81. package/docs/hooks.ja.md +0 -23
  82. package/docs/hooks.md +0 -23
  83. package/docs/hooks.zh-TW.md +0 -23
  84. package/docs/hooks.zh.md +0 -23
  85. package/docs/overview.ja.md +0 -119
  86. package/docs/overview.md +0 -119
  87. package/docs/overview.zh-TW.md +0 -119
  88. package/docs/overview.zh.md +0 -119
  89. package/docs/ui-components-address.ja.md +0 -121
  90. package/docs/ui-components-address.md +0 -121
  91. package/docs/ui-components-address.zh-TW.md +0 -121
  92. package/docs/ui-components-address.zh.md +0 -121
  93. package/docs/ui-components-avatar.ja.md +0 -65
  94. package/docs/ui-components-avatar.md +0 -65
  95. package/docs/ui-components-avatar.zh-TW.md +0 -65
  96. package/docs/ui-components-avatar.zh.md +0 -65
  97. package/docs/ui-components-button.ja.md +0 -99
  98. package/docs/ui-components-button.md +0 -99
  99. package/docs/ui-components-button.zh-TW.md +0 -99
  100. package/docs/ui-components-button.zh.md +0 -99
  101. package/docs/ui-components-logo.ja.md +0 -52
  102. package/docs/ui-components-logo.md +0 -52
  103. package/docs/ui-components-logo.zh-TW.md +0 -52
  104. package/docs/ui-components-logo.zh.md +0 -52
  105. package/docs/ui-components.ja.md +0 -57
  106. package/docs/ui-components.md +0 -57
  107. package/docs/ui-components.zh-TW.md +0 -57
  108. package/docs/ui-components.zh.md +0 -57
  109. package/glossary.md +0 -1
  110. package/src/Address/index.jsx +0 -2
  111. package/src/Avatar/index.jsx +0 -2
  112. package/src/Button/Button.stories.jsx +0 -7
  113. package/src/Button/index.jsx +0 -21
  114. package/src/Connect/Connect.stories.jsx +0 -34
  115. package/src/Connect/assets/locale.js +0 -149
  116. package/src/Connect/assets/login-bg.png +0 -0
  117. package/src/Connect/assets/login-slogan.js +0 -7
  118. package/src/Connect/components/action-button.jsx +0 -22
  119. package/src/Connect/components/app-tips.jsx +0 -156
  120. package/src/Connect/components/auto-height.jsx +0 -38
  121. package/src/Connect/components/back-button.jsx +0 -24
  122. package/src/Connect/components/connect-status.jsx +0 -259
  123. package/src/Connect/components/did-connect-title.jsx +0 -107
  124. package/src/Connect/components/download-tips.jsx +0 -55
  125. package/src/Connect/components/loading.jsx +0 -25
  126. package/src/Connect/components/login-item/connect-choose-list.jsx +0 -317
  127. package/src/Connect/components/login-item/connect-provider-list.jsx +0 -462
  128. package/src/Connect/components/login-item/login-method-item.jsx +0 -139
  129. package/src/Connect/components/login-item/mobile-login-item.jsx +0 -181
  130. package/src/Connect/components/login-item/passkey-login-item.jsx +0 -54
  131. package/src/Connect/components/login-item/wallet-login-options.jsx +0 -129
  132. package/src/Connect/components/login-item/web-login-item.jsx +0 -157
  133. package/src/Connect/components/mask-overlay.jsx +0 -32
  134. package/src/Connect/components/refresh-overlay.jsx +0 -52
  135. package/src/Connect/components/switch-app.jsx +0 -69
  136. package/src/Connect/connect.jsx +0 -617
  137. package/src/Connect/contexts/state.jsx +0 -234
  138. package/src/Connect/fallback-connect.jsx +0 -47
  139. package/src/Connect/fullpage.jsx +0 -3
  140. package/src/Connect/hooks/auth-url.js +0 -31
  141. package/src/Connect/hooks/method-list.js +0 -121
  142. package/src/Connect/hooks/page-show.js +0 -24
  143. package/src/Connect/hooks/provider-list.js +0 -165
  144. package/src/Connect/hooks/security.js +0 -40
  145. package/src/Connect/hooks/token.js +0 -627
  146. package/src/Connect/hooks/use-apps.js +0 -69
  147. package/src/Connect/hooks/use-quick-connect.js +0 -119
  148. package/src/Connect/index.jsx +0 -21
  149. package/src/Connect/landing-page.jsx +0 -3
  150. package/src/Connect/plugins/email/index.jsx +0 -85
  151. package/src/Connect/plugins/email/list-item.jsx +0 -34
  152. package/src/Connect/plugins/email/placeholder.jsx +0 -365
  153. package/src/Connect/plugins/index.js +0 -2
  154. package/src/Connect/use-connect.jsx +0 -321
  155. package/src/Connect/with-blocklet.jsx +0 -26
  156. package/src/Connect/with-bridge-call.jsx +0 -138
  157. package/src/Federated/context.jsx +0 -93
  158. package/src/Federated/index.jsx +0 -1
  159. package/src/Logo/index.jsx +0 -2
  160. package/src/OAuth/bind-conflict-alert.jsx +0 -37
  161. package/src/OAuth/context.jsx +0 -407
  162. package/src/OAuth/guest.svg +0 -20
  163. package/src/OAuth/index.jsx +0 -1
  164. package/src/OAuth/passport-switcher.jsx +0 -2
  165. package/src/Passkey/actions.jsx +0 -217
  166. package/src/Passkey/constants.js +0 -2
  167. package/src/Passkey/context.jsx +0 -395
  168. package/src/Passkey/dialog.jsx +0 -401
  169. package/src/Passkey/icon.jsx +0 -10
  170. package/src/Passkey/index.jsx +0 -2
  171. package/src/Service/index.jsx +0 -96
  172. package/src/Session/assets/did-spaces-guide-cover.svg +0 -1
  173. package/src/Session/assets/did-spaces-guide-icon.svg +0 -7
  174. package/src/Session/context.jsx +0 -7
  175. package/src/Session/did-spaces-guide.jsx +0 -173
  176. package/src/Session/handler.jsx +0 -98
  177. package/src/Session/hooks/use-federated.js +0 -91
  178. package/src/Session/hooks/use-mobile.jsx +0 -6
  179. package/src/Session/hooks/use-protected-routes.js +0 -16
  180. package/src/Session/hooks/use-session-token.js +0 -400
  181. package/src/Session/hooks/use-verify.jsx +0 -76
  182. package/src/Session/index.jsx +0 -1789
  183. package/src/Session/libs/constants.js +0 -17
  184. package/src/Session/libs/did-spaces.js +0 -38
  185. package/src/Session/libs/federated.js +0 -82
  186. package/src/Session/libs/index.js +0 -5
  187. package/src/Session/libs/locales.js +0 -160
  188. package/src/Session/libs/login-mobile.js +0 -80
  189. package/src/Session/window-focus-aware.jsx +0 -28
  190. package/src/SessionManager/index.jsx +0 -2
  191. package/src/Storage/engine/cookie.js +0 -25
  192. package/src/Storage/engine/local-storage.js +0 -57
  193. package/src/Storage/index.js +0 -25
  194. package/src/User/index.js +0 -4
  195. package/src/User/use-did.js +0 -80
  196. package/src/User/wrap-did.jsx +0 -18
  197. package/src/WebWalletSWKeeper/index.jsx +0 -3
  198. package/src/components/PassportSwitcher.jsx +0 -160
  199. package/src/constant.js +0 -27
  200. package/src/error.js +0 -6
  201. package/src/hooks/use-locale.jsx +0 -6
  202. package/src/index.js +0 -32
  203. package/src/locales/en.jsx +0 -15
  204. package/src/locales/index.jsx +0 -13
  205. package/src/locales/zh.jsx +0 -15
  206. package/src/types.d.ts +0 -355
  207. package/src/utils.js +0 -413
  208. package/vite.config.mjs +0 -29
@@ -1,173 +0,0 @@
1
- /* eslint-disable import/no-unresolved */
2
- /* eslint-disable jsx-a11y/anchor-is-valid */
3
- import React, { useState } from 'react';
4
- import {
5
- Dialog,
6
- DialogTitle,
7
- DialogContent,
8
- DialogActions,
9
- Button,
10
- ImageListItem,
11
- Typography,
12
- Stack,
13
- Box,
14
- CircularProgress,
15
- } from '@mui/material';
16
- import { useCreation, useReactive } from 'ahooks';
17
- import PropTypes from 'prop-types';
18
- import isUndefined from 'lodash/isUndefined';
19
- import noop from 'lodash/noop';
20
-
21
- import DIDSpacesGuideCoverSVG from './assets/did-spaces-guide-cover.svg?react';
22
- import DidSpacesGuideIcon from './assets/did-spaces-guide-icon.svg?react';
23
- import { useLocale } from '../hooks/use-locale';
24
- import { t } from '../locales';
25
- import useMobile from './hooks/use-mobile';
26
-
27
- /**
28
- * @typedef {{
29
- * autoClose?: true | false;
30
- * open?: boolean;
31
- * }} DIDSpacesGuideProps
32
- */
33
-
34
- /**
35
- * @type {React.ForwardRefExoticComponent<React.PropsWithoutRef<DIDSpacesGuideProps> & React.RefAttributes<HTMLDivElement>>}
36
- */
37
- function DIDSpacesGuideView({ ...rawProps }) {
38
- const props = Object.assign({}, rawProps);
39
- if (isUndefined(props.open)) {
40
- props.open = false;
41
- }
42
- if (isUndefined(props.onConnect)) {
43
- props.onConnect = noop;
44
- }
45
- const locale = useLocale();
46
- const isMobile = useMobile();
47
- const currentState = useReactive({
48
- loading: false,
49
- });
50
-
51
- const features = useCreation(() => {
52
- return [
53
- t('didSpacesGuide.feature.dataSecurity', locale),
54
- t('didSpacesGuide.feature.dataSharing', locale),
55
- t('didSpacesGuide.feature.dataSync', locale),
56
- t('didSpacesGuide.feature.dataIntegration', locale),
57
- ];
58
- }, []);
59
-
60
- return (
61
- <Dialog
62
- disableEscapeKeyDown
63
- aria-labelledby="alert-dialog-title"
64
- aria-describedby="alert-dialog-description"
65
- open={props.open}>
66
- <DialogTitle id="alert-dialog-title">
67
- <Typography
68
- sx={{
69
- fontSize: '20px',
70
- fontWeight: '500',
71
- }}>
72
- {t('didSpacesGuide.title', locale)}
73
- </Typography>
74
- <Typography
75
- sx={{
76
- fontSize: '14px',
77
- fontWeight: '300',
78
- color: '#9397A1',
79
- }}>
80
- {t('didSpacesGuide.description', locale)}
81
- </Typography>
82
- </DialogTitle>
83
- <DialogContent sx={{ padding: '12px 20px !important' }}>
84
- <ImageListItem sx={{ width: '100%' }}>
85
- <DIDSpacesGuideCoverSVG style={{ width: '100%', height: isMobile ? '100%' : '167px' }} />
86
- </ImageListItem>
87
- <Stack
88
- direction="row"
89
- sx={{
90
- justifyContent: 'space-between',
91
- width: '100%',
92
- padding: '16px',
93
- mt: 1,
94
- backgroundColor: '#F6F6F6',
95
- borderRadius: '8px',
96
- }}>
97
- {features.map((x) => {
98
- return (
99
- <Box key={x} sx={{ display: 'flex', flex: 1, padding: 'auto 16px' }}>
100
- <DidSpacesGuideIcon size="16px" />
101
- <Typography
102
- variant="body1"
103
- sx={{
104
- marginLeft: '1.5px',
105
- color: '#030712',
106
- fontFamily: 'Helvetica Neue',
107
- fontSize: '12px',
108
- fontStyle: 'normal',
109
- fontWeight: '400',
110
- lineHeight: 'normal',
111
- letterSpacing: '-0.12px',
112
- }}>
113
- {x}
114
- </Typography>
115
- </Box>
116
- );
117
- })}
118
- </Stack>
119
- </DialogContent>
120
- <DialogActions>
121
- <Button
122
- variant="contained"
123
- size="small"
124
- onClick={() => {
125
- currentState.loading = true;
126
- props.onConnect(() => {
127
- currentState.loading = false;
128
- });
129
- }}
130
- sx={{
131
- boxShadow: 'none',
132
- }}
133
- disabled={currentState.loading}>
134
- {currentState.loading ? <CircularProgress color="inherit" size={12} sx={{ mr: 1 }} /> : null}
135
- {t('didSpacesGuide.connectNow', locale)}
136
- </Button>
137
- </DialogActions>
138
- </Dialog>
139
- );
140
- }
141
-
142
- DIDSpacesGuideView.propTypes = {
143
- open: PropTypes.bool,
144
- onConnect: PropTypes.func,
145
- };
146
-
147
- /**
148
- *
149
- *
150
- * @export
151
- * @param {DIDSpacesGuideProps} [props={}]
152
- * @return {*}
153
- */
154
- export default function useDIDSpacesGuide(props = {}) {
155
- const [open, setOpen] = useState(false);
156
- const [onConnect, setOnConnect] = useState(() => {});
157
-
158
- const invokeOpen = () => {
159
- setOpen(true);
160
- };
161
-
162
- const invokeClose = () => {
163
- setOpen(false);
164
- };
165
-
166
- const invokeOnConnect = (callback) => {
167
- setOnConnect(() => callback);
168
- };
169
- return {
170
- DidSpacesGuideView: <DIDSpacesGuideView {...props} open={open} onConnect={onConnect} />,
171
- didSpacesGuideApi: { open: invokeOpen, close: invokeClose, onConnect: invokeOnConnect },
172
- };
173
- }
@@ -1,98 +0,0 @@
1
- import { ReactGA } from '@arcblock/ux/lib/withTracker';
2
- import { GA_LAST_LOGIN_METHOD, GA_LAST_ROLE, GA_LAST_SOURCE_PROVIDER } from '@arcblock/ux/lib/withTracker/constant';
3
-
4
- // 监听用户登录事件
5
- export const gaLoginSuccessHandler = () => {
6
- /**
7
- * @type {import('@arcblock/ux/lib/withTracker/action/login').LoginSuccessEvent}
8
- */
9
- const loginSuccessEvent = {
10
- action: 'loginSuccess',
11
- provider: localStorage.getItem(GA_LAST_LOGIN_METHOD),
12
- success: true,
13
- };
14
- ReactGA.event(loginSuccessEvent.action, loginSuccessEvent);
15
- };
16
-
17
- /**
18
- *
19
- * @param {Error} error
20
- */
21
- export const gaLoginFailedHandler = (error) => {
22
- /**
23
- * @type {import('@arcblock/ux/lib/withTracker/action/login').LoginFailedEvent}
24
- */
25
- const loginFailedEvent = {
26
- action: 'loginFailed',
27
- provider: localStorage.getItem(GA_LAST_LOGIN_METHOD),
28
- success: false,
29
- errorMessage: error.message,
30
- };
31
- ReactGA.event(loginFailedEvent.action, loginFailedEvent);
32
- };
33
-
34
- export const gaSwitchPassportSuccessHandler = (_result, _decrypt, session) => {
35
- const fromRole = localStorage.getItem(GA_LAST_ROLE);
36
- const toRole = session?.user?.role;
37
- const change = `${fromRole} -> ${toRole}`;
38
- /** @type {import('@arcblock/ux/lib/withTracker/action/switch-passport').SwitchPassportSuccessEvent} */
39
- const switchPassportSuccessEvent = {
40
- action: 'switchPassportSuccess',
41
- change,
42
- success: true,
43
- };
44
- ReactGA.event(switchPassportSuccessEvent.action, switchPassportSuccessEvent);
45
- };
46
-
47
- /**
48
- *
49
- * @param {Error} error
50
- */
51
- export const gaSwitchPassportFailedHandler = (error) => {
52
- /** @type {import('@arcblock/ux/lib/withTracker/action/switch-passport').SwitchPassportFailedEvent} */
53
- const switchPassportFailedEvent = {
54
- action: 'switchPassportFailed',
55
- success: false,
56
- errorMessage: error.message,
57
- };
58
- ReactGA.event(switchPassportFailedEvent.action, switchPassportFailedEvent);
59
- };
60
-
61
- /**
62
- *
63
- * @param {any} _result
64
- * @param {Function} _decrypt
65
- * @param {import('../types').SessionProps} session
66
- */
67
- /**
68
- *
69
- * @param {any} _result
70
- * @param {Function} _decrypt
71
- * @param {import('../types').SessionProps} session
72
- */
73
- export const gaBindWalletSuccessHandler = (_result, _decrypt, session) => {
74
- /**
75
- * @type {import('@arcblock/ux/lib/withTracker/action/bind-wallet').BindWalletSuccessEvent} */
76
- const bindWalletEvent = {
77
- action: 'bindWalletSuccess',
78
- provider: session?.user?.sourceProvider,
79
- success: true,
80
- };
81
- ReactGA.event(bindWalletEvent.action, bindWalletEvent);
82
- };
83
-
84
- /**
85
- * @param {Error} error
86
- * @param {import('../types').User} user
87
- */
88
- export const gaBindWalletFailedHandler = (error) => {
89
- /** @type {import('@arcblock/ux/lib/withTracker/action/bind-wallet').BindWalletFailedEvent} */
90
- const bindWalletFailedEvent = {
91
- action: 'bindWalletFailed',
92
- provider: localStorage.getItem(GA_LAST_SOURCE_PROVIDER),
93
- success: false,
94
- errorMessage: error.message,
95
- };
96
-
97
- ReactGA.event(bindWalletFailedEvent.action, bindWalletFailedEvent);
98
- };
@@ -1,91 +0,0 @@
1
- import { useMemoizedFn, useReactive } from 'ahooks';
2
- import { getConfig, getFederatedEnabled, getMaster } from '@arcblock/ux/lib/Util/federated';
3
- import noop from 'lodash/noop';
4
-
5
- import { loginFederatedMaster } from '../libs/federated';
6
-
7
- const translations = {
8
- zh: {
9
- notFoundFederatedInfo: '未发现统一登录的信息',
10
- autoLoginFederatedFailed: '自动登录统一登录账号失败',
11
- manualLoginFederatedFailed: '手动登录统一登录账号失败',
12
- },
13
- en: {
14
- notFoundFederatedInfo: 'No federated login info detected',
15
- autoLoginFederatedFailed: 'Auto login federated account failed',
16
- manualLoginFederatedFailed: 'Manual login federated account failed',
17
- },
18
- };
19
-
20
- export default function useFederated({ locale, handleLoginResult, login, handleRefreshUser }) {
21
- const state = useReactive({
22
- federatedMaster: null,
23
- });
24
- const federatedEnabled = getFederatedEnabled();
25
- const master = getMaster();
26
- const config = getConfig();
27
-
28
- /**
29
- * @deprecated no longer used
30
- */
31
- const loginFederated = useMemoizedFn(
32
- async (callback = noop, extraParams = {}, options = {}) => {
33
- // @compatible: 兼容旧的传递 origin 的方式
34
- if (typeof options === 'string') {
35
- // eslint-disable-next-line no-param-reassign
36
- options = { origin: options };
37
- }
38
- // eslint-disable-next-line prefer-const
39
- let { mode = 'auto', ...params } = extraParams;
40
- if (options.mode) {
41
- mode = options.mode;
42
- }
43
- // @compatible end
44
-
45
- if (mode === 'auto') {
46
- if (!federatedEnabled) {
47
- // NOTE: 这里的错误仅展示在控制台,不需要展示给用户看
48
- throw new Error(translations[locale].notFoundFederatedInfo);
49
- }
50
- try {
51
- // 自动登录的前提是:master 已经登录成功,这里需要通过 master 拿到 member 的登录 token
52
- // FIXME: @zhanghan 当 connect 组件使用不同的 baseUrl 时,不应该直接从 window.blocklet 去取值
53
- const data = await loginFederatedMaster({ appId: globalThis.blocklet.appId }, { fetchToken: false });
54
- handleLoginResult({ ...data, encrypted: false });
55
- await handleRefreshUser({ showProgress: true });
56
- callback();
57
- } catch (err) {
58
- const errMessage = err?.response ? err.response?.data : err?.message;
59
- callback(errMessage || translations[locale].autoLoginFederatedFailed);
60
- }
61
- } else if (mode === 'manual') {
62
- try {
63
- login(
64
- async () => {
65
- await loginFederatedMaster(
66
- // FIXME: @zhanghan 当 connect 组件使用不同的 baseUrl 时,不应该直接从 window.blocklet 去取值
67
- { appId: globalThis.blocklet.appId, onlyWriteCookie: true }
68
- );
69
- callback();
70
- },
71
- { ...params },
72
- options
73
- );
74
- } catch (err) {
75
- const errMessage = err?.response ? err.response?.data : err?.message;
76
- callback(errMessage || translations[locale].autoLoginFederatedFailed);
77
- }
78
- }
79
- },
80
- [handleRefreshUser, login, locale, handleLoginResult]
81
- );
82
-
83
- return {
84
- master,
85
- config,
86
- federatedMaster: state.federatedMaster,
87
- federatedEnabled,
88
- loginFederated,
89
- loginFederatedMaster,
90
- };
91
- }
@@ -1,6 +0,0 @@
1
- import { useTheme, useMediaQuery } from '@mui/material';
2
-
3
- export default function useMobile(key = 'sm') {
4
- const theme = useTheme();
5
- return useMediaQuery(theme.breakpoints.down(key));
6
- }
@@ -1,16 +0,0 @@
1
- import { useCreation, useMemoizedFn } from 'ahooks';
2
- import pathToRegexp from 'path-to-regexp';
3
-
4
- export default function useProtectedRoutes({ protectedRoutes = [] }) {
5
- const matchList = useCreation(() => {
6
- return protectedRoutes.map((item) => pathToRegexp(item, []));
7
- }, [protectedRoutes]);
8
-
9
- const checkMatch = useMemoizedFn((currentRoute = window.location.pathname) => {
10
- return matchList.some((item) => item.exec(currentRoute));
11
- });
12
-
13
- return {
14
- checkMatch,
15
- };
16
- }