@authing/react-ui-components 3.0.0-alpha → 3.0.0-rc.3

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 (232) hide show
  1. package/lib/index.d.ts +781 -110
  2. package/lib/index.min.css +2 -2
  3. package/lib/index.min.js +1 -1
  4. package/lib/index.min.js.LICENSE.txt +2 -0
  5. package/package.json +34 -12
  6. package/.eslintignore +0 -6
  7. package/.eslintrc.js +0 -7
  8. package/.prettierrc +0 -5
  9. package/.vscode/settings.json +0 -31
  10. package/build/favicon.ico +0 -0
  11. package/build/logo192.png +0 -0
  12. package/build/logo512.png +0 -0
  13. package/build/manifest.json +0 -25
  14. package/build/robots.txt +0 -3
  15. package/components/AuthingDropdown/index.tsx +0 -52
  16. package/components/AuthingDropdown/style.less +0 -43
  17. package/components/AuthingGuard/AppMFALayout/index.tsx +0 -74
  18. package/components/AuthingGuard/AppMFALayout/style.less +0 -12
  19. package/components/AuthingGuard/CompleteUserInfoLayout/index.tsx +0 -29
  20. package/components/AuthingGuard/CompleteUserInfoLayout/style.less +0 -8
  21. package/components/AuthingGuard/Forms/ADLoginForm/index.tsx +0 -117
  22. package/components/AuthingGuard/Forms/Agreements/index.tsx +0 -81
  23. package/components/AuthingGuard/Forms/Agreements/style.less +0 -44
  24. package/components/AuthingGuard/Forms/CompleteUserInfoForm/index.tsx +0 -139
  25. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/CheckEmailForm.tsx +0 -84
  26. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/VerifyCodeForm.tsx +0 -116
  27. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/index.tsx +0 -40
  28. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/style.less +0 -0
  29. package/components/AuthingGuard/Forms/EmailRegisterForm/index.tsx +0 -181
  30. package/components/AuthingGuard/Forms/EmailRegisterForm/style.less +0 -0
  31. package/components/AuthingGuard/Forms/LdapLoginForm/index.tsx +0 -166
  32. package/components/AuthingGuard/Forms/LdapLoginForm/style.less +0 -0
  33. package/components/AuthingGuard/Forms/LoginFormFooter/index.tsx +0 -76
  34. package/components/AuthingGuard/Forms/LoginFormFooter/style.less +0 -6
  35. package/components/AuthingGuard/Forms/MfaResetCodeForm/Step1.tsx +0 -86
  36. package/components/AuthingGuard/Forms/MfaResetCodeForm/Step2.tsx +0 -53
  37. package/components/AuthingGuard/Forms/MfaResetCodeForm/index.tsx +0 -65
  38. package/components/AuthingGuard/Forms/MfaResetCodeForm/style.less +0 -20
  39. package/components/AuthingGuard/Forms/MfaVerifyForm/index.tsx +0 -105
  40. package/components/AuthingGuard/Forms/MfaVerifyForm/style.less +0 -12
  41. package/components/AuthingGuard/Forms/PasswordLoginForm/index.tsx +0 -261
  42. package/components/AuthingGuard/Forms/PhoneCodeLoginForm/index.tsx +0 -133
  43. package/components/AuthingGuard/Forms/PhoneRegisterForm/index.tsx +0 -202
  44. package/components/AuthingGuard/Forms/QrCodeLoginForm/index.tsx +0 -59
  45. package/components/AuthingGuard/Forms/QrCodeLoginForm/style.less +0 -14
  46. package/components/AuthingGuard/Forms/RegisterFormFooter/index.tsx +0 -56
  47. package/components/AuthingGuard/Forms/RegisterFormFooter/style.less +0 -0
  48. package/components/AuthingGuard/Forms/ResetPwdForm/Footer.tsx +0 -21
  49. package/components/AuthingGuard/Forms/ResetPwdForm/Step1.tsx +0 -86
  50. package/components/AuthingGuard/Forms/ResetPwdForm/Step2.tsx +0 -127
  51. package/components/AuthingGuard/Forms/ResetPwdForm/Step3.tsx +0 -141
  52. package/components/AuthingGuard/Forms/ResetPwdForm/Step4.tsx +0 -51
  53. package/components/AuthingGuard/Forms/ResetPwdForm/index.tsx +0 -96
  54. package/components/AuthingGuard/Forms/ResetPwdForm/style.less +0 -3
  55. package/components/AuthingGuard/Forms/SendPhoneCode/SendCodeBtn.tsx +0 -88
  56. package/components/AuthingGuard/Forms/SendPhoneCode/index.tsx +0 -50
  57. package/components/AuthingGuard/Forms/SendPhoneCode/style.less +0 -26
  58. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/CheckPhoneForm.tsx +0 -86
  59. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/VerifyCodeForm.tsx +0 -113
  60. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/index.tsx +0 -40
  61. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/style.less +0 -3
  62. package/components/AuthingGuard/Forms/SocialAndIdpLogin/index.tsx +0 -325
  63. package/components/AuthingGuard/Forms/SocialAndIdpLogin/style.less +0 -75
  64. package/components/AuthingGuard/Forms/UploadImage/index.tsx +0 -70
  65. package/components/AuthingGuard/Forms/index.ts +0 -13
  66. package/components/AuthingGuard/GuardLayout/index.tsx +0 -474
  67. package/components/AuthingGuard/GuardLayout/style.less +0 -111
  68. package/components/AuthingGuard/Header/index.tsx +0 -25
  69. package/components/AuthingGuard/Header/style.less +0 -52
  70. package/components/AuthingGuard/IconFont/iconfont.js +0 -74
  71. package/components/AuthingGuard/IconFont/index.tsx +0 -19
  72. package/components/AuthingGuard/IconFont/style.less +0 -6
  73. package/components/AuthingGuard/IconFont/svg.js +0 -2
  74. package/components/AuthingGuard/LoginLayout/index.tsx +0 -161
  75. package/components/AuthingGuard/LoginLayout/style.less +0 -0
  76. package/components/AuthingGuard/MfaLayout/Steps.ts +0 -4
  77. package/components/AuthingGuard/MfaLayout/index.tsx +0 -49
  78. package/components/AuthingGuard/MfaLayout/style.less +0 -3
  79. package/components/AuthingGuard/RegisterLayout/index.tsx +0 -89
  80. package/components/AuthingGuard/RegisterLayout/style.less +0 -0
  81. package/components/AuthingGuard/ResetPwdLayout/index.tsx +0 -20
  82. package/components/AuthingGuard/ToggleLang/index.tsx +0 -51
  83. package/components/AuthingGuard/api/appConfig.ts +0 -146
  84. package/components/AuthingGuard/api/index.ts +0 -3
  85. package/components/AuthingGuard/api/sso.ts +0 -29
  86. package/components/AuthingGuard/api/userPoolConfig.ts +0 -111
  87. package/components/AuthingGuard/constants.ts +0 -105
  88. package/components/AuthingGuard/hooks/index.tsx +0 -70
  89. package/components/AuthingGuard/hooks/useScreenSize.tsx +0 -68
  90. package/components/AuthingGuard/index.tsx +0 -126
  91. package/components/AuthingGuard/style.less +0 -103
  92. package/components/AuthingGuard/types/Forms.ts +0 -94
  93. package/components/AuthingGuard/types/GuardConfig.ts +0 -420
  94. package/components/AuthingGuard/types/GuardState.ts +0 -7
  95. package/components/AuthingGuard/types/Locales.ts +0 -12
  96. package/components/AuthingGuard/types/index.ts +0 -4
  97. package/components/AuthingTabs/index.tsx +0 -98
  98. package/components/AuthingTabs/style.less +0 -135
  99. package/components/BindTotp/core/bindSuccess.tsx +0 -61
  100. package/components/BindTotp/core/securityCode.tsx +0 -119
  101. package/components/BindTotp/index.tsx +0 -134
  102. package/components/BindTotp/props.ts +0 -30
  103. package/components/BindTotp/styles.less +0 -56
  104. package/components/ChangeLanguage/index.tsx +0 -35
  105. package/components/ChangePassword/core/firstLoginReset.tsx +0 -104
  106. package/components/ChangePassword/core/rotateReset.tsx +0 -114
  107. package/components/ChangePassword/index.tsx +0 -59
  108. package/components/CompleteInfo/core/completeInfo.tsx +0 -155
  109. package/components/CompleteInfo/index.tsx +0 -45
  110. package/components/CompleteInfo/props.ts +0 -40
  111. package/components/CompleteInfo/styles.less +0 -7
  112. package/components/CompleteUserInfo/index.tsx +0 -49
  113. package/components/CompleteUserInfo/props.ts +0 -25
  114. package/components/ComponentsRender/index.back +0 -64
  115. package/components/CopyAbleText/index.tsx +0 -54
  116. package/components/CopyAbleText/style.less +0 -13
  117. package/components/DownloadAuthenticator/index.tsx +0 -97
  118. package/components/DownloadAuthenticator/props.ts +0 -22
  119. package/components/DownloadAuthenticator/styles.less +0 -52
  120. package/components/ForgetPassword/core/resetPassword.tsx +0 -150
  121. package/components/ForgetPassword/index.tsx +0 -51
  122. package/components/Guard/Guard.tsx +0 -226
  123. package/components/Guard/authClient.ts +0 -55
  124. package/components/Guard/config.ts +0 -19
  125. package/components/Guard/event.ts +0 -18
  126. package/components/Guard/index.tsx +0 -10
  127. package/components/Guard/module.ts +0 -19
  128. package/components/Guard/stateMachine.ts +0 -133
  129. package/components/Guard/styles.less +0 -444
  130. package/components/IconFont/iconfont.js +0 -74
  131. package/components/IconFont/index.tsx +0 -16
  132. package/components/IconFont/style.less +0 -6
  133. package/components/IconFont/svg.js +0 -2
  134. package/components/ImagePro/index.tsx +0 -52
  135. package/components/ImagePro/styles.less +0 -40
  136. package/components/Login/codemap.ts +0 -35
  137. package/components/Login/core/withAD.tsx +0 -9
  138. package/components/Login/core/withAppQrcode.tsx +0 -49
  139. package/components/Login/core/withLDAP.tsx +0 -145
  140. package/components/Login/core/withPassword.tsx +0 -176
  141. package/components/Login/core/withPhonecode.tsx +0 -135
  142. package/components/Login/core/withWechatMiniQrcode.tsx +0 -60
  143. package/components/Login/core/withWechatmpQrcode.tsx +0 -53
  144. package/components/Login/index.tsx +0 -359
  145. package/components/Login/props.ts +0 -90
  146. package/components/Login/socialLogin/index.tsx +0 -413
  147. package/components/Login/socialLogin/style.less +0 -61
  148. package/components/Login/styles.less +0 -53
  149. package/components/MFA/codemap.ts +0 -21
  150. package/components/MFA/core/email.tsx +0 -226
  151. package/components/MFA/core/face.tsx +0 -297
  152. package/components/MFA/core/face_deps.tsx +0 -37
  153. package/components/MFA/core/sms.tsx +0 -222
  154. package/components/MFA/core/totp.tsx +0 -137
  155. package/components/MFA/index.tsx +0 -135
  156. package/components/MFA/mfaMethods/index.tsx +0 -81
  157. package/components/MFA/mfaMethods/style.less +0 -39
  158. package/components/MFA/props.ts +0 -51
  159. package/components/MFA/styles.less +0 -92
  160. package/components/NeedHelpView/core/describeQuestions.tsx +0 -227
  161. package/components/NeedHelpView/index.tsx +0 -99
  162. package/components/RecoveryCode/core/useCode.tsx +0 -71
  163. package/components/RecoveryCode/index.tsx +0 -27
  164. package/components/RecoveryCode/interface.ts +0 -31
  165. package/components/RecoveryCode/style.less +0 -13
  166. package/components/Register/codemap.ts +0 -16
  167. package/components/Register/components/Agreements/index.tsx +0 -81
  168. package/components/Register/components/Agreements/style.less +0 -44
  169. package/components/Register/core/WithEmail.tsx +0 -250
  170. package/components/Register/core/WithPhone.tsx +0 -190
  171. package/components/Register/index.tsx +0 -122
  172. package/components/Register/props.ts +0 -50
  173. package/components/SendCode/SendCodeBtn.tsx +0 -96
  174. package/components/SendCode/index.tsx +0 -98
  175. package/components/SendCode/style.less +0 -31
  176. package/components/ShieldSpin/index.tsx +0 -27
  177. package/components/ShieldSpin/loading.svg +0 -29
  178. package/components/SubmitButton/index.tsx +0 -50
  179. package/components/Type/index.ts +0 -61
  180. package/components/VerifyCodeInput/index.tsx +0 -76
  181. package/components/VerifyCodeInput/style.less +0 -24
  182. package/components/_utils/GuardErrorCode.ts +0 -8
  183. package/components/_utils/clipboard.ts +0 -27
  184. package/components/_utils/config.ts +0 -123
  185. package/components/_utils/guradHttp.ts +0 -93
  186. package/components/_utils/hooks/index.ts +0 -56
  187. package/components/_utils/http.ts +0 -85
  188. package/components/_utils/index.ts +0 -310
  189. package/components/_utils/locales/en/common.json +0 -218
  190. package/components/_utils/locales/en/index.ts +0 -6
  191. package/components/_utils/locales/en/login.json +0 -95
  192. package/components/_utils/locales/en/map.json +0 -4
  193. package/components/_utils/locales/en/user.json +0 -82
  194. package/components/_utils/locales/index.ts +0 -45
  195. package/components/_utils/locales/zh/common.json +0 -218
  196. package/components/_utils/locales/zh/index.ts +0 -6
  197. package/components/_utils/locales/zh/login.json +0 -95
  198. package/components/_utils/locales/zh/map.json +0 -4
  199. package/components/_utils/locales/zh/user.json +0 -82
  200. package/components/_utils/popupCenter.ts +0 -48
  201. package/components/context/base.tsx +0 -28
  202. package/components/context/global/context.tsx +0 -39
  203. package/components/context/global/reducer.tsx +0 -56
  204. package/components/context/module/context.tsx +0 -23
  205. package/components/index.ts +0 -10
  206. package/config/antdReplacer.js +0 -51
  207. package/config/env.js +0 -104
  208. package/config/getHttpsConfig.js +0 -66
  209. package/config/jest/cssTransform.js +0 -14
  210. package/config/jest/fileTransform.js +0 -40
  211. package/config/modules.js +0 -134
  212. package/config/paths.js +0 -71
  213. package/config/pnpTs.js +0 -35
  214. package/config/webpack.config.js +0 -835
  215. package/config/webpackDevServer.config.js +0 -130
  216. package/examples.tsx +0 -100
  217. package/index.js +0 -1
  218. package/logo.svg +0 -7
  219. package/public/favicon.ico +0 -0
  220. package/public/index.html +0 -43
  221. package/public/logo192.png +0 -0
  222. package/public/logo512.png +0 -0
  223. package/public/manifest.json +0 -25
  224. package/public/robots.txt +0 -3
  225. package/react-app-env.d.ts +0 -71
  226. package/reportWebVitals.ts +0 -15
  227. package/scripts/build.js +0 -208
  228. package/scripts/lib.js +0 -200
  229. package/scripts/start.js +0 -162
  230. package/scripts/test.js +0 -49
  231. package/setupTests.ts +0 -5
  232. package/tsconfig.json +0 -30
@@ -1,75 +0,0 @@
1
- .authing-guard-third-login-btn {
2
- display: inline-flex;
3
- justify-content: center;
4
- align-items: center;
5
- }
6
-
7
- .authing-social-login-item {
8
- display: inline-flex;
9
- margin: 8px 8px;
10
- width: 48px;
11
- height: 48px;
12
- background-color: #eff1f6;
13
- border-radius: 50%;
14
- justify-content: center;
15
- align-items: center;
16
- cursor: pointer;
17
- user-select: none;
18
-
19
- .authing-icon {
20
- font-size: 20px;
21
- color: #aeb9d4;
22
- transition: color 0.3s ease-in-out;
23
- }
24
-
25
- &:hover .authing-icon {
26
- color: #396aff;
27
- }
28
- }
29
-
30
- .authing-social-login-title {
31
- text-align: center;
32
- font-size: 14px;
33
- color: #999999;
34
- }
35
-
36
- .authing-social-login-title::before,
37
- .authing-social-login-title::after {
38
- content: '——';
39
- color: #eeeeee;
40
- margin: 0 11px;
41
- }
42
-
43
- .authing-social-login-list {
44
- display: flex;
45
- flex-wrap: wrap;
46
- justify-content: center;
47
- }
48
-
49
- @media only screen and (max-width: 719px) {
50
- .authing-social-login-title {
51
- font-size: 12px;
52
- }
53
- .authing-social-login-item {
54
- width: 32px;
55
- height: 32px;
56
- .authing-icon {
57
- font-size: 16px;
58
- }
59
- }
60
- .authing-guard-full-width-space {
61
- .authing-ant-space-item {
62
- margin-bottom: 16px !important;
63
- display: flex;
64
- justify-content: center;
65
- .authing-ant-btn {
66
- width: 200px;
67
- height: 34px;
68
- background: #ffffff;
69
- border-radius: 18px;
70
- border: 1px solid #e7e7e7;
71
- font-size: 12px;
72
- }
73
- }
74
- }
75
- }
@@ -1,70 +0,0 @@
1
- import { PlusOutlined } from '@ant-design/icons'
2
- import { message, Spin, Upload } from 'antd'
3
- import { UploadChangeParam } from 'antd/lib/upload'
4
- import React, { FC, useState } from 'react'
5
- import { useTranslation } from 'react-i18next'
6
- import { useGuardContext } from '../../../context/global/context'
7
-
8
- export const UploadImage: FC<{
9
- value?: string
10
- onChange?: (value: string) => void
11
- }> = ({ value, onChange }) => {
12
- const [uploading, setUploading] = useState(false)
13
- const { t } = useTranslation()
14
- const {
15
- state: {
16
- config: { apiHost },
17
- },
18
- } = useGuardContext()
19
-
20
- const onStatusChange = (info: UploadChangeParam) => {
21
- const { status } = info.file
22
-
23
- if (status === 'uploading') {
24
- setUploading(true)
25
- } else {
26
- setUploading(false)
27
- }
28
-
29
- if (status === 'done') {
30
- const { code, message: errMsg, data } = info.file.response
31
- if (code !== 200) {
32
- return message.error(errMsg)
33
- }
34
- const { url } = data
35
- onChange?.(url)
36
- } else if (status === 'error') {
37
- message.error(
38
- t('common.uploadFail', {
39
- name: info.file.name,
40
- })
41
- )
42
- }
43
- }
44
-
45
- const uploadButton = (
46
- <div>
47
- <PlusOutlined />
48
- <div style={{ marginTop: 8 }}>Upload</div>
49
- </div>
50
- )
51
-
52
- return (
53
- <Upload
54
- name="file"
55
- accept="image/*"
56
- listType="picture-card"
57
- showUploadList={false}
58
- action={`${apiHost}/api/v2/upload?folder=photos`}
59
- onChange={onStatusChange}
60
- >
61
- <Spin size="small" spinning={uploading}>
62
- {value ? (
63
- <img src={value} alt="" style={{ width: '100%' }} />
64
- ) : (
65
- uploadButton
66
- )}
67
- </Spin>
68
- </Upload>
69
- )
70
- }
@@ -1,13 +0,0 @@
1
- export * from './ADLoginForm'
2
- export * from './ResetPwdForm'
3
- export * from './MfaVerifyForm'
4
- export * from './LdapLoginForm'
5
- export * from './QrCodeLoginForm'
6
- export * from './MfaResetCodeForm'
7
- export * from './EmailRegisterForm'
8
- export * from './PhoneRegisterForm'
9
- export * from './PasswordLoginForm'
10
- export * from './SocialAndIdpLogin'
11
- export * from './PhoneCodeLoginForm'
12
- export * from './SmsMfaVerifyForm'
13
- export * from './EmailMfaVerifyForm'
@@ -1,474 +0,0 @@
1
- import { message, Spin } from 'antd'
2
- import React, { FC, useCallback, useEffect, useMemo, useState } from 'react'
3
-
4
- import {
5
- getClassnames,
6
- insertStyles,
7
- deepMerge,
8
- removeStyles,
9
- } from '../../_utils'
10
- import { useGuardContext } from '../../context/global/context'
11
- import { GuardHeader } from '../../../components/AuthingGuard/Header'
12
- import { MfaLayout } from '../../../components/AuthingGuard/MfaLayout'
13
- import { LoginLayout } from '../../../components/AuthingGuard/LoginLayout'
14
- import {
15
- defaultGuardConfig,
16
- HIDE_SOCIALS,
17
- } from '../../../components/AuthingGuard/constants'
18
- import { RegisterLayout } from '../../../components/AuthingGuard/RegisterLayout'
19
- import { ResetPwdLayout } from '../../../components/AuthingGuard/ResetPwdLayout'
20
- import {
21
- SessionData,
22
- trackSession,
23
- fetchAppConfig,
24
- ApplicationConfig,
25
- SocialConnectionItem,
26
- } from '../../../components/AuthingGuard/api'
27
- import {
28
- GuardMode,
29
- GuardScenes,
30
- GuardConfig,
31
- UserConfig,
32
- Lang,
33
- } from '../../../components/AuthingGuard/types'
34
-
35
- import './style.less'
36
- import { CompleteUserInfoLayout } from '../CompleteUserInfoLayout'
37
- import { AppMfaLayout } from '../AppMFALayout'
38
- import { IconFont } from '../IconFont'
39
- import { ToggleLang } from '../ToggleLang'
40
- import { useTranslation } from 'react-i18next'
41
- import i18n from 'i18next'
42
- import { changeLang } from '../../_utils/locales'
43
-
44
- const checkConfig = (appId: string) => {
45
- // 不要去掉 console.warn,不然 vue 版打包出来每次都会 throw error,估计是 rollup 打包有问题
46
- if (!appId) {
47
- console.warn('APP ID: ', appId)
48
- throw new Error(i18n.t('common.unAppId'))
49
- }
50
- }
51
-
52
- const useGuardConfig = () => {
53
- const {
54
- state: { appId, userConfig },
55
- setValue,
56
- } = useGuardContext()
57
-
58
- const { t } = useTranslation()
59
-
60
- const [loading, setLoading] = useState(true)
61
-
62
- const [appConfig, setAppConfig] = useState<Partial<ApplicationConfig>>({})
63
- const [errorMsg, setErrorMsg] = useState('')
64
- const [errorDetail, setErrorDetail] = useState<any>()
65
-
66
- useEffect(() => {
67
- try {
68
- checkConfig(appId)
69
-
70
- setErrorDetail(null)
71
- setErrorMsg('')
72
- } catch (e: any) {
73
- setErrorDetail(e)
74
- setErrorMsg(e.message)
75
- console.error(e)
76
- }
77
- }, [appId])
78
-
79
- // 获取应用配置
80
- useEffect(() => {
81
- setLoading(true)
82
-
83
- if (!appId) {
84
- setLoading(false)
85
- return
86
- }
87
- fetchAppConfig(appId)
88
- .then((res) => {
89
- if (res.code !== 200) {
90
- setErrorMsg(res.message!)
91
- setErrorDetail(res)
92
- return
93
- }
94
-
95
- setAppConfig(res.data!)
96
- setValue('userPoolId', res.data?.userPoolId)
97
- })
98
- .catch((e: any) => {
99
- setErrorDetail(e)
100
- setErrorMsg(t('common.networkError'))
101
- })
102
- .finally(() => {
103
- setLoading(false)
104
- })
105
-
106
- // eslint-disable-next-line react-hooks/exhaustive-deps
107
- }, [appId])
108
-
109
- useEffect(() => {
110
- // 先移除之前的
111
- removeStyles('appConfig')
112
- removeStyles('userConfig')
113
-
114
- insertStyles(appConfig?.css, 'appConfig')
115
- insertStyles(userConfig.contentCss, 'userConfig')
116
- }, [appConfig, userConfig.contentCss])
117
-
118
- const guardConfig = useMemo<GuardConfig>(() => {
119
- /**
120
- * 将用应用配置与用户手动传入的配置合并
121
- * 优先级:用户传入 > 应用 > 用户池
122
- */
123
-
124
- // 社会化登录
125
- let socialConnectionObjs: SocialConnectionItem[] | undefined
126
- // 默认展示所有社会化登录
127
- if (!userConfig.socialConnections) {
128
- socialConnectionObjs = [...(appConfig.socialConnections || [])]
129
- } else {
130
- const socials = userConfig.socialConnections
131
- socialConnectionObjs = appConfig.socialConnections?.filter?.((item) =>
132
- socials.includes(item.provider)
133
- )
134
- }
135
-
136
- // 某些社会化登录会在 tabs 中显示,或者无法在 Guard 中使用,所以底部不显示了
137
- socialConnectionObjs = socialConnectionObjs?.filter(
138
- (item) => !HIDE_SOCIALS.includes(item.provider)
139
- )
140
-
141
- // 企业身份源
142
- let enterpriseConnectionObjs: ApplicationConfig['identityProviders']
143
-
144
- if (userConfig.enterpriseConnections) {
145
- enterpriseConnectionObjs =
146
- appConfig.identityProviders?.filter?.((item) =>
147
- userConfig.enterpriseConnections!.includes(item.identifier)
148
- ) || []
149
- } else {
150
- enterpriseConnectionObjs = appConfig.identityProviders || []
151
- }
152
-
153
- // 登录方式
154
- const loginMethods =
155
- userConfig.loginMethods ||
156
- appConfig.loginTabs?.list ||
157
- defaultGuardConfig.loginMethods
158
-
159
- // 账密登录的登录拆分
160
- const passwordLoginMethods =
161
- userConfig.passwordLoginMethods ||
162
- appConfig.passwordTabConfig?.enabledLoginMethods ||
163
- defaultGuardConfig.loginMethods
164
-
165
- // 默认登录方式
166
- const defaultLoginMethod =
167
- userConfig.defaultLoginMethod ||
168
- appConfig.loginTabs?.default ||
169
- defaultGuardConfig.defaultLoginMethod
170
-
171
- // 注册方式
172
- const registerMethods =
173
- userConfig.registerMethods ||
174
- appConfig.registerTabs?.list ||
175
- defaultGuardConfig.registerMethods
176
- // 默认注册方式
177
- const defaultRegisterMethod =
178
- userConfig.defaultRegisterMethod ||
179
- appConfig.registerTabs?.default ||
180
- defaultGuardConfig.defaultRegisterMethod
181
-
182
- // 应用名
183
- const title = loading
184
- ? ''
185
- : userConfig.title ?? appConfig.name ?? defaultGuardConfig.title
186
-
187
- // 应用 logo
188
- const logo = loading
189
- ? ''
190
- : userConfig.logo ?? appConfig.logo ?? defaultGuardConfig.logo
191
-
192
- // 是否自动注册
193
- const autoRegister =
194
- userConfig.autoRegister ??
195
- appConfig.ssoPageComponentDisplay?.autoRegisterThenLoginHintInfo ??
196
- defaultGuardConfig.autoRegister
197
-
198
- // 禁止注册
199
- const disableRegister =
200
- userConfig.disableRegister ??
201
- !(
202
- appConfig.ssoPageComponentDisplay?.registerBtn ??
203
- !defaultGuardConfig.disableRegister
204
- )
205
-
206
- // 禁止重置密码
207
- const disableResetPwd =
208
- userConfig.disableResetPwd ??
209
- !(
210
- appConfig.ssoPageComponentDisplay?.registerBtn ??
211
- !defaultGuardConfig.disableResetPwd
212
- )
213
-
214
- return deepMerge<GuardConfig>(
215
- {} as GuardConfig,
216
- defaultGuardConfig,
217
- userConfig,
218
- {
219
- logo,
220
- title,
221
- autoRegister,
222
- loginMethods,
223
- passwordLoginMethods,
224
- extendsFields: appConfig.extendsFields,
225
- disableRegister,
226
- disableResetPwd,
227
- registerMethods,
228
- defaultLoginMethod,
229
- socialConnectionObjs,
230
- defaultRegisterMethod,
231
- enterpriseConnectionObjs,
232
- publicKey: appConfig.publicKey,
233
- agreementEnabled: appConfig.agreementEnabled,
234
- agreements: appConfig.agreements,
235
- }
236
- )
237
- }, [
238
- userConfig,
239
- appConfig.loginTabs?.list,
240
- appConfig.loginTabs?.default,
241
- appConfig.passwordTabConfig?.enabledLoginMethods,
242
- appConfig.registerTabs?.list,
243
- appConfig.registerTabs?.default,
244
- appConfig.name,
245
- appConfig.logo,
246
- appConfig.ssoPageComponentDisplay?.autoRegisterThenLoginHintInfo,
247
- appConfig.ssoPageComponentDisplay?.registerBtn,
248
- appConfig.extendsFields,
249
- appConfig.publicKey,
250
- appConfig.agreementEnabled,
251
- appConfig.agreements,
252
- appConfig.socialConnections,
253
- appConfig.identityProviders,
254
- loading,
255
- ])
256
-
257
- return {
258
- loading,
259
- errorMsg,
260
- guardConfig,
261
- errorDetail,
262
- }
263
- }
264
-
265
- const useModal = (visible?: boolean) => {
266
- const {
267
- state: { userConfig },
268
- } = useGuardContext()
269
-
270
- const isModal = userConfig.mode === GuardMode.Modal
271
- // 传入了 visible 则为受控组件
272
- const isControlled = typeof visible !== 'undefined'
273
-
274
- // modal 模式,没传 visible,默认为 true
275
- const [localVisible, setLocalVisible] = useState(
276
- isModal && isControlled ? visible : true
277
- )
278
-
279
- const toggleLocalVisible = () => {
280
- setLocalVisible((v) => !v)
281
- }
282
-
283
- const realVisible = useMemo(() => {
284
- return isControlled ? visible : localVisible
285
- }, [isControlled, localVisible, visible])
286
-
287
- return {
288
- isModal,
289
- realVisible,
290
- isControlled,
291
- toggleLocalVisible,
292
- }
293
- }
294
-
295
- export const GuardLayout: FC<{
296
- visible?: boolean
297
- className?: string
298
- id?: string
299
- style?: React.CSSProperties
300
- lang?: Lang
301
- // 这个传下是为了响应 config 变化,好蠢,以后优化
302
- userConfig: UserConfig
303
- }> = ({
304
- visible,
305
- id,
306
- className,
307
- style,
308
- lang,
309
- userConfig: reactiveUserConfig,
310
- }) => {
311
- const { t } = useTranslation()
312
- const {
313
- state: { guardScenes, authClient, guardEvents, activeTabs, localesConfig },
314
- setValue,
315
- } = useGuardContext()
316
-
317
- const { realVisible, isControlled, toggleLocalVisible } = useModal(visible)
318
-
319
- const { loading, errorMsg, guardConfig, errorDetail } = useGuardConfig()
320
-
321
- useEffect(() => {
322
- if (lang) {
323
- authClient.setLang(lang)
324
- changeLang(lang)
325
- }
326
- }, [authClient, lang])
327
-
328
- useEffect(() => {
329
- if (!loading) {
330
- guardEvents.onLoginTabChange?.(activeTabs.login)
331
- }
332
- }, [activeTabs.login, loading, guardEvents])
333
-
334
- useEffect(() => {
335
- if (!loading) {
336
- guardEvents.onRegisterTabChange?.(activeTabs.register)
337
- }
338
- }, [activeTabs.register, loading, guardEvents])
339
-
340
- useEffect(() => {
341
- setValue('userConfig', reactiveUserConfig)
342
- }, [reactiveUserConfig, setValue])
343
-
344
- // 动画完成后完全隐藏 dom
345
- const [hidden, setHidden] = useState(false)
346
- useEffect(() => {
347
- setHidden(false)
348
- }, [realVisible])
349
-
350
- const closeHandler = useCallback(() => {
351
- if (!isControlled && realVisible) {
352
- toggleLocalVisible()
353
- }
354
- guardEvents.onClose?.()
355
- }, [isControlled, guardEvents, toggleLocalVisible, realVisible])
356
-
357
- useEffect(() => {
358
- if (loading) {
359
- return
360
- }
361
- if (errorDetail) {
362
- guardEvents.onLoadError?.(errorDetail)
363
- return
364
- }
365
-
366
- guardEvents.onLoad?.(authClient)
367
- }, [authClient, errorDetail, guardEvents, loading, t])
368
-
369
- useEffect(() => {
370
- if (guardConfig.isSSO) {
371
- trackSession().then((sessionData) => {
372
- // 这个接口没有 code, data, 直接返回了数据
373
- let typedData = (sessionData as unknown) as SessionData
374
- if (typedData.userInfo) {
375
- message.success(t('common.LoginSuccess'))
376
- guardEvents.onLogin?.(typedData.userInfo, authClient)
377
- }
378
- })
379
- }
380
- }, [guardConfig.isSSO, guardEvents, authClient, t])
381
-
382
- useEffect(() => {
383
- setValue('config', guardConfig)
384
- setValue('activeTabs', {
385
- [GuardScenes.Login]: guardConfig.defaultLoginMethod,
386
- [GuardScenes.Register]: guardConfig.defaultRegisterMethod,
387
- })
388
- // eslint-disable-next-line react-hooks/exhaustive-deps
389
- }, [guardConfig])
390
-
391
- const isModal = useMemo(() => guardConfig.mode === GuardMode.Modal, [
392
- guardConfig,
393
- ])
394
-
395
- // 监听 esc 关闭 modal
396
- useEffect(() => {
397
- const handler = (evt: KeyboardEvent) => {
398
- if (evt.keyCode === 27 && isModal && guardConfig.escCloseable) {
399
- closeHandler()
400
- }
401
- }
402
-
403
- window.addEventListener('keydown', handler)
404
- return () => window.removeEventListener('keydown', handler)
405
- }, [closeHandler, guardConfig, isModal])
406
-
407
- const layoutMap = {
408
- [GuardScenes.Login]: <LoginLayout />,
409
- [GuardScenes.Register]: <RegisterLayout />,
410
- [GuardScenes.RestPassword]: <ResetPwdLayout />,
411
- [GuardScenes.MfaVerify]: <MfaLayout />,
412
- [GuardScenes.CompleteUserInfo]: <CompleteUserInfoLayout />,
413
- [GuardScenes.AppMfaVerify]: <AppMfaLayout />,
414
- }
415
-
416
- return (
417
- <div
418
- id={id}
419
- style={{
420
- ...style,
421
- zIndex: guardConfig.zIndex || 100,
422
- }}
423
- className={getClassnames([
424
- 'authing-guard-layout',
425
- !realVisible && 'authing-guard-layout__hidden',
426
- isModal && 'authing-guard-layout__modal',
427
- hidden && 'authing-guard-layout__dis-none',
428
- className,
429
- ])}
430
- onTransitionEnd={() => {
431
- if (!realVisible) {
432
- setHidden(true)
433
- }
434
- }}
435
- >
436
- <>
437
- {isModal && (
438
- <div
439
- className={getClassnames([
440
- 'authing-guard-mask',
441
- !realVisible && 'authing-guard-mask__hidden',
442
- ])}
443
- ></div>
444
- )}
445
- <div
446
- className={getClassnames([
447
- 'authing-guard-container',
448
- !realVisible && 'authing-guard-container__hidden',
449
- ])}
450
- >
451
- {isModal && guardConfig.clickCloseable && (
452
- <button onClick={closeHandler} className="authing-guard-close-btn">
453
- <IconFont type="authing-guanbi" />
454
- </button>
455
- )}
456
-
457
- <GuardHeader />
458
-
459
- {loading ? (
460
- <Spin size="large" className="authing-guard-loading" />
461
- ) : errorMsg ? (
462
- <div className="authing-guard-load-error">{errorMsg}</div>
463
- ) : (
464
- layoutMap[guardScenes]
465
- )}
466
- {/* <div>{localesConfig?.isShowChange && <ToggleLang />}</div> */}
467
- <div>
468
- {localesConfig?.isShowChange === false ? null : <ToggleLang />}
469
- </div>
470
- </div>
471
- </>
472
- </div>
473
- )
474
- }