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

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 (235) hide show
  1. package/dist/index.min.css +2 -0
  2. package/dist/index.min.js +2 -0
  3. package/dist/index.min.js.LICENSE.txt +71 -0
  4. package/{components/ShieldSpin/loading.svg → dist/static/media/loading.4a67a5f3.svg} +0 -0
  5. package/lib/index.d.ts +2108 -118
  6. package/lib/index.min.css +2 -2
  7. package/lib/index.min.js +1 -1
  8. package/lib/index.min.js.LICENSE.txt +2 -0
  9. package/package.json +32 -10
  10. package/.eslintignore +0 -6
  11. package/.eslintrc.js +0 -7
  12. package/.prettierrc +0 -5
  13. package/.vscode/settings.json +0 -31
  14. package/build/favicon.ico +0 -0
  15. package/build/logo192.png +0 -0
  16. package/build/logo512.png +0 -0
  17. package/build/manifest.json +0 -25
  18. package/build/robots.txt +0 -3
  19. package/components/AuthingDropdown/index.tsx +0 -52
  20. package/components/AuthingDropdown/style.less +0 -43
  21. package/components/AuthingGuard/AppMFALayout/index.tsx +0 -74
  22. package/components/AuthingGuard/AppMFALayout/style.less +0 -12
  23. package/components/AuthingGuard/CompleteUserInfoLayout/index.tsx +0 -29
  24. package/components/AuthingGuard/CompleteUserInfoLayout/style.less +0 -8
  25. package/components/AuthingGuard/Forms/ADLoginForm/index.tsx +0 -117
  26. package/components/AuthingGuard/Forms/Agreements/index.tsx +0 -81
  27. package/components/AuthingGuard/Forms/Agreements/style.less +0 -44
  28. package/components/AuthingGuard/Forms/CompleteUserInfoForm/index.tsx +0 -139
  29. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/CheckEmailForm.tsx +0 -84
  30. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/VerifyCodeForm.tsx +0 -116
  31. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/index.tsx +0 -40
  32. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/style.less +0 -0
  33. package/components/AuthingGuard/Forms/EmailRegisterForm/index.tsx +0 -181
  34. package/components/AuthingGuard/Forms/EmailRegisterForm/style.less +0 -0
  35. package/components/AuthingGuard/Forms/LdapLoginForm/index.tsx +0 -166
  36. package/components/AuthingGuard/Forms/LdapLoginForm/style.less +0 -0
  37. package/components/AuthingGuard/Forms/LoginFormFooter/index.tsx +0 -76
  38. package/components/AuthingGuard/Forms/LoginFormFooter/style.less +0 -6
  39. package/components/AuthingGuard/Forms/MfaResetCodeForm/Step1.tsx +0 -86
  40. package/components/AuthingGuard/Forms/MfaResetCodeForm/Step2.tsx +0 -53
  41. package/components/AuthingGuard/Forms/MfaResetCodeForm/index.tsx +0 -65
  42. package/components/AuthingGuard/Forms/MfaResetCodeForm/style.less +0 -20
  43. package/components/AuthingGuard/Forms/MfaVerifyForm/index.tsx +0 -105
  44. package/components/AuthingGuard/Forms/MfaVerifyForm/style.less +0 -12
  45. package/components/AuthingGuard/Forms/PasswordLoginForm/index.tsx +0 -261
  46. package/components/AuthingGuard/Forms/PhoneCodeLoginForm/index.tsx +0 -133
  47. package/components/AuthingGuard/Forms/PhoneRegisterForm/index.tsx +0 -202
  48. package/components/AuthingGuard/Forms/QrCodeLoginForm/index.tsx +0 -59
  49. package/components/AuthingGuard/Forms/QrCodeLoginForm/style.less +0 -14
  50. package/components/AuthingGuard/Forms/RegisterFormFooter/index.tsx +0 -56
  51. package/components/AuthingGuard/Forms/RegisterFormFooter/style.less +0 -0
  52. package/components/AuthingGuard/Forms/ResetPwdForm/Footer.tsx +0 -21
  53. package/components/AuthingGuard/Forms/ResetPwdForm/Step1.tsx +0 -86
  54. package/components/AuthingGuard/Forms/ResetPwdForm/Step2.tsx +0 -127
  55. package/components/AuthingGuard/Forms/ResetPwdForm/Step3.tsx +0 -141
  56. package/components/AuthingGuard/Forms/ResetPwdForm/Step4.tsx +0 -51
  57. package/components/AuthingGuard/Forms/ResetPwdForm/index.tsx +0 -96
  58. package/components/AuthingGuard/Forms/ResetPwdForm/style.less +0 -3
  59. package/components/AuthingGuard/Forms/SendPhoneCode/SendCodeBtn.tsx +0 -88
  60. package/components/AuthingGuard/Forms/SendPhoneCode/index.tsx +0 -50
  61. package/components/AuthingGuard/Forms/SendPhoneCode/style.less +0 -26
  62. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/CheckPhoneForm.tsx +0 -86
  63. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/VerifyCodeForm.tsx +0 -113
  64. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/index.tsx +0 -40
  65. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/style.less +0 -3
  66. package/components/AuthingGuard/Forms/SocialAndIdpLogin/index.tsx +0 -325
  67. package/components/AuthingGuard/Forms/SocialAndIdpLogin/style.less +0 -75
  68. package/components/AuthingGuard/Forms/UploadImage/index.tsx +0 -70
  69. package/components/AuthingGuard/Forms/index.ts +0 -13
  70. package/components/AuthingGuard/GuardLayout/index.tsx +0 -474
  71. package/components/AuthingGuard/GuardLayout/style.less +0 -111
  72. package/components/AuthingGuard/Header/index.tsx +0 -25
  73. package/components/AuthingGuard/Header/style.less +0 -52
  74. package/components/AuthingGuard/IconFont/iconfont.js +0 -74
  75. package/components/AuthingGuard/IconFont/index.tsx +0 -19
  76. package/components/AuthingGuard/IconFont/style.less +0 -6
  77. package/components/AuthingGuard/IconFont/svg.js +0 -2
  78. package/components/AuthingGuard/LoginLayout/index.tsx +0 -161
  79. package/components/AuthingGuard/LoginLayout/style.less +0 -0
  80. package/components/AuthingGuard/MfaLayout/Steps.ts +0 -4
  81. package/components/AuthingGuard/MfaLayout/index.tsx +0 -49
  82. package/components/AuthingGuard/MfaLayout/style.less +0 -3
  83. package/components/AuthingGuard/RegisterLayout/index.tsx +0 -89
  84. package/components/AuthingGuard/RegisterLayout/style.less +0 -0
  85. package/components/AuthingGuard/ResetPwdLayout/index.tsx +0 -20
  86. package/components/AuthingGuard/ToggleLang/index.tsx +0 -51
  87. package/components/AuthingGuard/api/appConfig.ts +0 -146
  88. package/components/AuthingGuard/api/index.ts +0 -3
  89. package/components/AuthingGuard/api/sso.ts +0 -29
  90. package/components/AuthingGuard/api/userPoolConfig.ts +0 -111
  91. package/components/AuthingGuard/constants.ts +0 -105
  92. package/components/AuthingGuard/hooks/index.tsx +0 -70
  93. package/components/AuthingGuard/hooks/useScreenSize.tsx +0 -68
  94. package/components/AuthingGuard/index.tsx +0 -126
  95. package/components/AuthingGuard/style.less +0 -103
  96. package/components/AuthingGuard/types/Forms.ts +0 -94
  97. package/components/AuthingGuard/types/GuardConfig.ts +0 -420
  98. package/components/AuthingGuard/types/GuardState.ts +0 -7
  99. package/components/AuthingGuard/types/Locales.ts +0 -12
  100. package/components/AuthingGuard/types/index.ts +0 -4
  101. package/components/AuthingTabs/index.tsx +0 -98
  102. package/components/AuthingTabs/style.less +0 -135
  103. package/components/BindTotp/core/bindSuccess.tsx +0 -61
  104. package/components/BindTotp/core/securityCode.tsx +0 -119
  105. package/components/BindTotp/index.tsx +0 -134
  106. package/components/BindTotp/props.ts +0 -30
  107. package/components/BindTotp/styles.less +0 -56
  108. package/components/ChangeLanguage/index.tsx +0 -35
  109. package/components/ChangePassword/core/firstLoginReset.tsx +0 -104
  110. package/components/ChangePassword/core/rotateReset.tsx +0 -114
  111. package/components/ChangePassword/index.tsx +0 -59
  112. package/components/CompleteInfo/core/completeInfo.tsx +0 -155
  113. package/components/CompleteInfo/index.tsx +0 -45
  114. package/components/CompleteInfo/props.ts +0 -40
  115. package/components/CompleteInfo/styles.less +0 -7
  116. package/components/CompleteUserInfo/index.tsx +0 -49
  117. package/components/CompleteUserInfo/props.ts +0 -25
  118. package/components/ComponentsRender/index.back +0 -64
  119. package/components/CopyAbleText/index.tsx +0 -54
  120. package/components/CopyAbleText/style.less +0 -13
  121. package/components/DownloadAuthenticator/index.tsx +0 -97
  122. package/components/DownloadAuthenticator/props.ts +0 -22
  123. package/components/DownloadAuthenticator/styles.less +0 -52
  124. package/components/ForgetPassword/core/resetPassword.tsx +0 -150
  125. package/components/ForgetPassword/index.tsx +0 -51
  126. package/components/Guard/Guard.tsx +0 -226
  127. package/components/Guard/authClient.ts +0 -55
  128. package/components/Guard/config.ts +0 -19
  129. package/components/Guard/event.ts +0 -18
  130. package/components/Guard/index.tsx +0 -10
  131. package/components/Guard/module.ts +0 -19
  132. package/components/Guard/stateMachine.ts +0 -133
  133. package/components/Guard/styles.less +0 -444
  134. package/components/IconFont/iconfont.js +0 -74
  135. package/components/IconFont/index.tsx +0 -16
  136. package/components/IconFont/style.less +0 -6
  137. package/components/IconFont/svg.js +0 -2
  138. package/components/ImagePro/index.tsx +0 -52
  139. package/components/ImagePro/styles.less +0 -40
  140. package/components/Login/codemap.ts +0 -35
  141. package/components/Login/core/withAD.tsx +0 -9
  142. package/components/Login/core/withAppQrcode.tsx +0 -49
  143. package/components/Login/core/withLDAP.tsx +0 -145
  144. package/components/Login/core/withPassword.tsx +0 -176
  145. package/components/Login/core/withPhonecode.tsx +0 -135
  146. package/components/Login/core/withWechatMiniQrcode.tsx +0 -60
  147. package/components/Login/core/withWechatmpQrcode.tsx +0 -53
  148. package/components/Login/index.tsx +0 -359
  149. package/components/Login/props.ts +0 -90
  150. package/components/Login/socialLogin/index.tsx +0 -413
  151. package/components/Login/socialLogin/style.less +0 -61
  152. package/components/Login/styles.less +0 -53
  153. package/components/MFA/codemap.ts +0 -21
  154. package/components/MFA/core/email.tsx +0 -226
  155. package/components/MFA/core/face.tsx +0 -297
  156. package/components/MFA/core/face_deps.tsx +0 -37
  157. package/components/MFA/core/sms.tsx +0 -222
  158. package/components/MFA/core/totp.tsx +0 -137
  159. package/components/MFA/index.tsx +0 -135
  160. package/components/MFA/mfaMethods/index.tsx +0 -81
  161. package/components/MFA/mfaMethods/style.less +0 -39
  162. package/components/MFA/props.ts +0 -51
  163. package/components/MFA/styles.less +0 -92
  164. package/components/NeedHelpView/core/describeQuestions.tsx +0 -227
  165. package/components/NeedHelpView/index.tsx +0 -99
  166. package/components/RecoveryCode/core/useCode.tsx +0 -71
  167. package/components/RecoveryCode/index.tsx +0 -27
  168. package/components/RecoveryCode/interface.ts +0 -31
  169. package/components/RecoveryCode/style.less +0 -13
  170. package/components/Register/codemap.ts +0 -16
  171. package/components/Register/components/Agreements/index.tsx +0 -81
  172. package/components/Register/components/Agreements/style.less +0 -44
  173. package/components/Register/core/WithEmail.tsx +0 -250
  174. package/components/Register/core/WithPhone.tsx +0 -190
  175. package/components/Register/index.tsx +0 -122
  176. package/components/Register/props.ts +0 -50
  177. package/components/SendCode/SendCodeBtn.tsx +0 -96
  178. package/components/SendCode/index.tsx +0 -98
  179. package/components/SendCode/style.less +0 -31
  180. package/components/ShieldSpin/index.tsx +0 -27
  181. package/components/SubmitButton/index.tsx +0 -50
  182. package/components/Type/index.ts +0 -61
  183. package/components/VerifyCodeInput/index.tsx +0 -76
  184. package/components/VerifyCodeInput/style.less +0 -24
  185. package/components/_utils/GuardErrorCode.ts +0 -8
  186. package/components/_utils/clipboard.ts +0 -27
  187. package/components/_utils/config.ts +0 -123
  188. package/components/_utils/guradHttp.ts +0 -93
  189. package/components/_utils/hooks/index.ts +0 -56
  190. package/components/_utils/http.ts +0 -85
  191. package/components/_utils/index.ts +0 -310
  192. package/components/_utils/locales/en/common.json +0 -218
  193. package/components/_utils/locales/en/index.ts +0 -6
  194. package/components/_utils/locales/en/login.json +0 -95
  195. package/components/_utils/locales/en/map.json +0 -4
  196. package/components/_utils/locales/en/user.json +0 -82
  197. package/components/_utils/locales/index.ts +0 -45
  198. package/components/_utils/locales/zh/common.json +0 -218
  199. package/components/_utils/locales/zh/index.ts +0 -6
  200. package/components/_utils/locales/zh/login.json +0 -95
  201. package/components/_utils/locales/zh/map.json +0 -4
  202. package/components/_utils/locales/zh/user.json +0 -82
  203. package/components/_utils/popupCenter.ts +0 -48
  204. package/components/context/base.tsx +0 -28
  205. package/components/context/global/context.tsx +0 -39
  206. package/components/context/global/reducer.tsx +0 -56
  207. package/components/context/module/context.tsx +0 -23
  208. package/components/index.ts +0 -10
  209. package/config/antdReplacer.js +0 -51
  210. package/config/env.js +0 -104
  211. package/config/getHttpsConfig.js +0 -66
  212. package/config/jest/cssTransform.js +0 -14
  213. package/config/jest/fileTransform.js +0 -40
  214. package/config/modules.js +0 -134
  215. package/config/paths.js +0 -71
  216. package/config/pnpTs.js +0 -35
  217. package/config/webpack.config.js +0 -835
  218. package/config/webpackDevServer.config.js +0 -130
  219. package/examples.tsx +0 -100
  220. package/index.js +0 -1
  221. package/logo.svg +0 -7
  222. package/public/favicon.ico +0 -0
  223. package/public/index.html +0 -43
  224. package/public/logo192.png +0 -0
  225. package/public/logo512.png +0 -0
  226. package/public/manifest.json +0 -25
  227. package/public/robots.txt +0 -3
  228. package/react-app-env.d.ts +0 -71
  229. package/reportWebVitals.ts +0 -15
  230. package/scripts/build.js +0 -208
  231. package/scripts/lib.js +0 -200
  232. package/scripts/start.js +0 -162
  233. package/scripts/test.js +0 -49
  234. package/setupTests.ts +0 -5
  235. package/tsconfig.json +0 -30
@@ -1,150 +0,0 @@
1
- import React, { useRef, useState } from 'react'
2
- import { useTranslation } from 'react-i18next'
3
- import { Form, Input } from 'antd'
4
- import { StoreValue } from 'antd/lib/form/interface'
5
-
6
- import { UserOutlined, SafetyOutlined, LockOutlined } from '@ant-design/icons'
7
- import { SendCode } from '../../SendCode'
8
-
9
- import { useAuthClient } from '../../Guard/authClient'
10
- import { getPasswordValidate, validate } from '../../_utils'
11
- import SubmitButton from '../../SubmitButton'
12
-
13
- interface ResetPasswordProps {
14
- onReset: any
15
- publicConfig: any
16
- }
17
- export const ResetPassword = (props: ResetPasswordProps) => {
18
- const { t } = useTranslation()
19
- let [form] = Form.useForm()
20
- let [identify, setIdentify] = useState('')
21
- let [codeMethod, setCodeMethod] = useState<'phone' | 'email'>('phone')
22
- let client = useAuthClient()
23
- let submitButtonRef = useRef<any>(null)
24
-
25
- const onFinish = async (values: any) => {
26
- let identify = values.identify
27
- let code = values.code
28
- let newPassword = values.password
29
- let context = new Promise(() => {})
30
-
31
- if (codeMethod === 'email') {
32
- // let r = await
33
- context = client.resetPasswordByEmailCode(identify, code, newPassword)
34
- }
35
- if (codeMethod === 'phone') {
36
- context = client.resetPasswordByPhoneCode(identify, code, newPassword)
37
- }
38
-
39
- context
40
- .then((r) => {
41
- props.onReset(r)
42
- })
43
- .catch((e) => {
44
- props.onReset(e)
45
- })
46
- }
47
-
48
- return (
49
- <div className="authing-g2-login-phone-code">
50
- <Form
51
- name="resetPassword"
52
- form={form}
53
- onFinish={onFinish}
54
- onFinishFailed={() => {
55
- submitButtonRef?.current?.onError()
56
- }}
57
- autoComplete="off"
58
- >
59
- <Form.Item
60
- className="authing-g2-input-form"
61
- name="identify"
62
- rules={[
63
- { required: true, message: t('login.inputPhoneOrEmail') },
64
- {
65
- validator: async (_, value: StoreValue) => {
66
- if (!value) {
67
- return
68
- }
69
- if (validate('email', value) || validate('phone', value)) {
70
- return
71
- } else {
72
- throw new Error(t('login.inputCorrectPhone'))
73
- }
74
- },
75
- },
76
- ]}
77
- >
78
- <Input
79
- className="authing-g2-input"
80
- autoComplete="tel"
81
- size="large"
82
- placeholder={t('login.inputPhoneOrEmail')}
83
- value={identify}
84
- onChange={(e) => {
85
- let v = e.target.value
86
- setIdentify(v)
87
- if (validate('email', v)) {
88
- setCodeMethod('email')
89
- }
90
- if (validate('phone', v)) {
91
- setCodeMethod('phone')
92
- }
93
- }}
94
- prefix={<UserOutlined style={{ color: '#878A95' }} />}
95
- />
96
- </Form.Item>
97
- <Form.Item
98
- className="authing-g2-input-form"
99
- name="code"
100
- rules={[{ required: true, message: t('common.inputVerifyCode') }]}
101
- >
102
- <SendCode
103
- className="authing-g2-input"
104
- autoComplete="one-time-code"
105
- size="large"
106
- placeholder={t('common.inputFourVerifyCode', {
107
- length: 4,
108
- })}
109
- prefix={<SafetyOutlined style={{ color: '#878A95' }} />}
110
- method={codeMethod}
111
- data={identify}
112
- // form={form}
113
- />
114
- </Form.Item>
115
- <Form.Item
116
- className="authing-g2-input-form"
117
- name="password"
118
- rules={[
119
- {
120
- validator(_, value) {
121
- if (value.indexOf(' ') !== -1) {
122
- return Promise.reject(t('common.checkPasswordHasSpace'))
123
- }
124
- return Promise.resolve()
125
- },
126
- },
127
- ...getPasswordValidate(
128
- props.publicConfig?.passwordStrength,
129
- props.publicConfig?.customPasswordStrength
130
- ),
131
- ]}
132
- >
133
- <Input.Password
134
- className="authing-g2-input"
135
- size="large"
136
- placeholder={t('user.inputNewPwd')}
137
- prefix={<LockOutlined style={{ color: '#878A95' }} />}
138
- />
139
- </Form.Item>
140
- <Form.Item className="authing-g2-input-form submit-form">
141
- <SubmitButton
142
- className="forget-password"
143
- text={t('common.confirm')}
144
- ref={submitButtonRef}
145
- />
146
- </Form.Item>
147
- </Form>
148
- </div>
149
- )
150
- }
@@ -1,51 +0,0 @@
1
- import React from 'react'
2
- import { useTranslation } from 'react-i18next'
3
- import { message } from 'antd'
4
-
5
- import { GuardModuleType } from '../Guard/module'
6
- import { ResetPassword } from './core/resetPassword'
7
-
8
- import { ImagePro } from '../ImagePro'
9
-
10
- export const GuardForgetPassword = (props: any) => {
11
- const { t } = useTranslation()
12
- let publicConfig = props.config.__publicConfig__
13
-
14
- const onReset = (res: any) => {
15
- let code = res.code
16
- if ([2001, 2004].includes(code)) {
17
- message.error(res.message)
18
- return
19
- }
20
- // 返回登录
21
- props.__changeModule(GuardModuleType.LOGIN)
22
- }
23
-
24
- return (
25
- <div className="g2-view-container">
26
- <div className="g2-view-header">
27
- <ImagePro
28
- src={props.config?.logo}
29
- size={48}
30
- borderRadius={4}
31
- alt=""
32
- className="icon"
33
- />
34
- {/* <img src={props.config?.logo} alt="" className="icon" /> */}
35
- <div className="title">{t('login.resetPwd')}</div>
36
- <div className="title-explain">{t('user.resetpasswordText1')}</div>
37
- </div>
38
- <div className="g2-view-tabs">
39
- <ResetPassword onReset={onReset} publicConfig={publicConfig} />
40
- </div>
41
- <div className="g2-tips-line">
42
- <div
43
- className="link-like back-to-login"
44
- onClick={() => props.__changeModule(GuardModuleType.LOGIN)}
45
- >
46
- {t('login.otherAccLogin')}
47
- </div>
48
- </div>
49
- </div>
50
- )
51
- }
@@ -1,226 +0,0 @@
1
- import React, {
2
- useCallback,
3
- useEffect,
4
- useMemo,
5
- useReducer,
6
- useState,
7
- } from 'react'
8
- import { ConfigProvider, Modal } from 'antd'
9
-
10
- import { GuardLoginView } from '../Login'
11
-
12
- import { initAuthClient } from './authClient'
13
- import { GuardEvents, guardEventsFilter } from './event'
14
- import { initConfig, GuardConfig } from '../_utils/config'
15
- import { initGuardHttp } from '../_utils/guradHttp'
16
- import { initI18n } from '..//_utils/locales'
17
- import { GuardMode, IG2FCProps } from '../Type'
18
- import { getDefaultGuardConfig } from './config'
19
- import { ShieldSpin } from '../ShieldSpin'
20
- import { GuardModuleType } from './module'
21
- import { GuardMFAView } from '../MFA'
22
- import { GuardRegisterView } from '../Register'
23
- import { GuardDownloadATView } from '../DownloadAuthenticator'
24
- import { GuardStateMachine, useHistoryHijack } from './stateMachine'
25
- import { GuardBindTotpView } from '../BindTotp'
26
- import { GuardForgetPassword } from '../ForgetPassword'
27
- import { GuardChangePassword } from '../ChangePassword'
28
- import { GuardNeedHelpView } from '../NeedHelpView'
29
- import { GuardCompleteInfoView } from '../CompleteInfo'
30
- import { GuardRecoveryCodeView } from '../RecoveryCode'
31
- import './styles.less'
32
- import { IconFont } from '../AuthingGuard/IconFont'
33
-
34
- const PREFIX_CLS = 'authing-ant'
35
-
36
- const ComponentsMapping: Record<
37
- GuardModuleType,
38
- (props: GuardViewProps) => React.ReactNode
39
- > = {
40
- [GuardModuleType.ERROR]: (props) => <div>Todo Error Module</div>,
41
- [GuardModuleType.LOGIN]: (props) => <GuardLoginView {...props} />,
42
- [GuardModuleType.MFA]: (props) => <GuardMFAView {...props} />,
43
- [GuardModuleType.REGISTER]: (props) => <GuardRegisterView {...props} />,
44
- [GuardModuleType.DOWNLOAD_AT]: (props) => <GuardDownloadATView {...props} />,
45
- [GuardModuleType.FORGET_PWD]: (props) => <GuardForgetPassword {...props} />,
46
- [GuardModuleType.CHANGE_PWD]: (props) => <GuardChangePassword {...props} />,
47
- [GuardModuleType.BIND_TOTP]: (props) => <GuardBindTotpView {...props} />,
48
- [GuardModuleType.ANY_QUESTIONS]: (props) => <GuardNeedHelpView {...props} />,
49
- [GuardModuleType.COMPLETE_INFO]: (props) => (
50
- <GuardCompleteInfoView {...props} />
51
- ),
52
- [GuardModuleType.RECOVERY_CODE]: (props) => (
53
- <GuardRecoveryCodeView {...props} />
54
- ),
55
- }
56
-
57
- export interface GuardProps extends GuardEvents, IG2FCProps {
58
- config?: Partial<GuardConfig>
59
- visible?: boolean
60
- }
61
-
62
- interface GuardViewProps extends GuardProps {
63
- config: GuardConfig
64
- initData: any
65
- }
66
-
67
- interface IBaseAction<T = string, P = any> {
68
- type: T & string
69
- payload?: Partial<P>
70
- }
71
-
72
- interface ModuleState {
73
- moduleName: GuardModuleType
74
- initData: any
75
- }
76
-
77
- export const Guard = (props: GuardProps) => {
78
- const { appId, config, onLoad, onLoadError } = props
79
-
80
- // 整合一下 所有的事件
81
- const events = guardEventsFilter(props)
82
-
83
- // 初始化 Loading 标识
84
- const [initSettingEnd, setInitSettingEnd] = useState(false)
85
-
86
- // Config
87
- const [guardConfig, setGuardConfig] = useState<GuardConfig>(
88
- getDefaultGuardConfig()
89
- )
90
-
91
- // 状态机
92
- const [
93
- guardStateMachine,
94
- setGuardStateMachine,
95
- ] = useState<GuardStateMachine>()
96
-
97
- // 劫持浏览器 History
98
- const [historyNext] = useHistoryHijack(guardStateMachine?.back)
99
-
100
- // 首页 init 数据
101
- const initState: ModuleState = {
102
- moduleName: GuardModuleType.LOGIN,
103
- initData: {},
104
- }
105
-
106
- // modules 定义
107
- const moduleReducer: (
108
- state: ModuleState,
109
- action: IBaseAction<GuardModuleType, ModuleState>
110
- ) => ModuleState = (state, { type, payload }) => {
111
- return {
112
- moduleName: type,
113
- initData: payload?.initData,
114
- }
115
- }
116
-
117
- // Modules Reducer
118
- const [moduleState, changeModule] = useReducer(moduleReducer, initState)
119
-
120
- // 切换 Module
121
- const onChangeModule = (moduleName: GuardModuleType, initData: any = {}) => {
122
- changeModule({
123
- type: moduleName,
124
- payload: {
125
- initData: initData ?? {},
126
- },
127
- })
128
- }
129
-
130
- // 初始化 Guard 一系列的东西
131
- const initGuardSetting = useCallback(async () => {
132
- try {
133
- // Config 初始化
134
- const { config: mergedConfig, publicConfig } = await initConfig(
135
- appId,
136
- config ?? {},
137
- getDefaultGuardConfig()
138
- )
139
-
140
- setGuardConfig(mergedConfig)
141
-
142
- // Rest 初始化
143
- const httpClient = initGuardHttp(mergedConfig?.host!)
144
- httpClient.setAppId(appId)
145
- httpClient.setUserpoolId(publicConfig.userPoolId)
146
-
147
- // TODO 国际化 这部分有点小问题 等待优化
148
- initI18n({}, mergedConfig.lang)
149
-
150
- // Authing JS SDK
151
- const authClient = initAuthClient(mergedConfig, appId)
152
-
153
- onLoad?.(authClient)
154
-
155
- // 状态机 初始化
156
- const guardStateMachine = new GuardStateMachine(onChangeModule, initState)
157
- guardStateMachine.setConfig(mergedConfig)
158
- setGuardStateMachine(guardStateMachine)
159
-
160
- // 初始化 结束
161
- setInitSettingEnd(true)
162
- } catch (error: any) {
163
- onLoadError?.(error)
164
-
165
- console.error(error)
166
- }
167
- // eslint-disable-next-line react-hooks/exhaustive-deps
168
- }, [appId, config, onLoad, onLoadError])
169
-
170
- useEffect(() => {
171
- initGuardSetting()
172
- }, [initGuardSetting])
173
-
174
- const renderModule = useMemo(() => {
175
- if (initSettingEnd) {
176
- return ComponentsMapping[moduleState.moduleName]({
177
- appId,
178
- initData: moduleState.initData,
179
- config: guardConfig,
180
- ...events,
181
- __changeModule: (moduleName, initData) => {
182
- historyNext(initData)
183
- guardStateMachine?.next(moduleName, initData)
184
- },
185
- })
186
- } else {
187
- return (
188
- <div className="g2-init-setting-loading">
189
- <ShieldSpin size={100} />
190
- </div>
191
- )
192
- }
193
- }, [
194
- appId,
195
- events,
196
- guardConfig,
197
- guardStateMachine,
198
- historyNext,
199
- initSettingEnd,
200
- moduleState.initData,
201
- moduleState.moduleName,
202
- ])
203
-
204
- return (
205
- // TODO 这部分缺失 Loging 态
206
- <ConfigProvider prefixCls={PREFIX_CLS}>
207
- {config?.mode === GuardMode.Modal ? (
208
- <Modal
209
- className="authing-g2-render-module-modal"
210
- closeIcon={
211
- <IconFont type="authing-close-line" className="g2-modal-close" />
212
- }
213
- visible={props.visible}
214
- onCancel={props.onClose}
215
- keyboard={config.escCloseable}
216
- maskClosable={true} //点击蒙层,是否允许关闭
217
- getContainer={config.target ? config.target : false}
218
- >
219
- <div className="authing-g2-render-module">{renderModule}</div>
220
- </Modal>
221
- ) : (
222
- <div className="authing-g2-render-module">{renderModule}</div>
223
- )}
224
- </ConfigProvider>
225
- )
226
- }
@@ -1,55 +0,0 @@
1
- import { message } from 'antd'
2
- import { AuthenticationClient } from 'authing-js-sdk'
3
- import { ErrorCode } from '../_utils/GuardErrorCode'
4
-
5
- import packageConfig from '../../package.json'
6
- import { GuardConfig } from './config'
7
-
8
- let authClient: AuthenticationClient
9
-
10
- export const initAuthClient = (config: GuardConfig, appId: string) => {
11
- const host = config.__appHost__ ?? config.host
12
- const lang = config.lang
13
-
14
- if (!authClient) {
15
- try {
16
- authClient = new AuthenticationClient({
17
- appHost: host,
18
- appId,
19
- lang,
20
- requestFrom: `Guard-${packageConfig.framework}@${packageConfig.version}`,
21
- onError: (code, msg: any) => {
22
- if (code === 2020) {
23
- return
24
- }
25
-
26
- if ([ErrorCode.USER_EXISTENCE].includes(code)) {
27
- message.error(msg)
28
- } else {
29
- message.error(msg)
30
- }
31
-
32
- // if ([ErrorCode.OTP_MFA_CODE, ErrorCode.APP_MFA_CODE].includes(code)) {
33
- // message.info(msg)
34
- // return
35
- // }
36
- // message.error(msg)
37
- },
38
- })
39
- } catch (error) {
40
- throw error
41
- }
42
- }
43
-
44
- return authClient
45
- }
46
-
47
- export const getAuthClient = () => {
48
- if (!authClient) {
49
- throw new Error('Please initialize AuthClient')
50
- }
51
-
52
- return authClient
53
- }
54
-
55
- export const useAuthClient = () => getAuthClient()
@@ -1,19 +0,0 @@
1
- import { getDefaultLoginConfig, LoginConfig } from '../Login/props'
2
- import { getDefaultRegisterConfig, RegisterConfig } from '../Register/props'
3
-
4
- export interface GuardComponentConifg extends Partial<GuardConfig> {}
5
-
6
- export interface GuardConfig extends RegisterConfig, LoginConfig {}
7
-
8
- let defaultConfig: GuardConfig
9
-
10
- export const getDefaultGuardConfig = (): GuardConfig => {
11
- if (!defaultConfig) {
12
- defaultConfig = {
13
- ...getDefaultLoginConfig(),
14
- ...getDefaultRegisterConfig(),
15
- }
16
- }
17
-
18
- return defaultConfig
19
- }
@@ -1,18 +0,0 @@
1
- import { CompleteInfoEvents } from '../CompleteInfo/props'
2
- import { LoginEvents } from '../Login/props'
3
- import { RegisterEvents } from '../Register/props'
4
-
5
- export interface GuardEvents
6
- extends LoginEvents,
7
- RegisterEvents,
8
- CompleteInfoEvents {}
9
-
10
- export const guardEventsFilter = (props: any) => {
11
- const events: GuardEvents = {}
12
- const eventsName = Object.keys(props).filter((name) => name.startsWith('on'))
13
- eventsName.forEach((eventName) => {
14
- events[eventName as keyof GuardEvents] = props[eventName]
15
- })
16
-
17
- return events
18
- }
@@ -1,10 +0,0 @@
1
- import { Guard, GuardProps } from './Guard'
2
- import { GuardModuleType } from './module'
3
- import { GuardComponentConifg } from './config'
4
- import { GuardEvents } from './event'
5
-
6
- export type { GuardProps, GuardModuleType, GuardComponentConifg, GuardEvents }
7
-
8
- export { Guard }
9
-
10
- export default Guard
@@ -1,19 +0,0 @@
1
- export enum GuardModuleType {
2
- ERROR = 'error',
3
- LOGIN = 'login',
4
- REGISTER = 'register',
5
- MFA = 'mfa',
6
- FORGET_PWD = 'forgetPassword',
7
- CHANGE_PWD = 'changePassword',
8
- DOWNLOAD_AT = 'downloadAT',
9
- BIND_TOTP = 'bindTotp',
10
- ANY_QUESTIONS = 'anyQuestions',
11
- COMPLETE_INFO = 'completeInfo',
12
- RECOVERY_CODE = 'recoveryCode',
13
- }
14
- export interface GuardModuleAction {
15
- action: string
16
- module?: GuardModuleType
17
- message?: string
18
- initData?: any
19
- }
@@ -1,133 +0,0 @@
1
- import { useEffect } from 'react'
2
- import { GuardComponentConifg, GuardConfig } from './config'
3
- import { GuardModuleType } from './module'
4
- const window: Window = require('global/window')
5
-
6
- export interface ModuleState {
7
- moduleName: GuardModuleType
8
- initData?: any
9
- }
10
-
11
- export enum ActionType {
12
- ChangeModule = 'ChangeModule',
13
- Back = 'Back',
14
- Init = 'Init',
15
- }
16
-
17
- export interface StateMachineLog {
18
- action: ActionType
19
- date: number
20
- dataSource: ModuleState
21
- }
22
-
23
- export type ChangeModuleEvent = (
24
- nextModelu: GuardModuleType,
25
- initData?: any
26
- ) => void
27
- export class GuardStateMachine {
28
- // 计数器
29
- private order: number = 0
30
-
31
- // 总体的配置信息
32
- private config: GuardComponentConifg = {}
33
-
34
- // 历史记录
35
- private moduleStateHistory: ModuleState[] = []
36
-
37
- private changeMouleEvent: ChangeModuleEvent
38
-
39
- // Log
40
- private stateMachineLog: Record<number, StateMachineLog> = {}
41
-
42
- constructor(changeMouleEvent: ChangeModuleEvent, initData: ModuleState) {
43
- this.changeMouleEvent = changeMouleEvent
44
-
45
- this.historyPush(initData, ActionType.Init)
46
- }
47
- globalWindow = (): Window | undefined =>
48
- typeof window !== undefined ? window : undefined
49
-
50
- next = (nextModelu: GuardModuleType, initData: any) => {
51
- const moduleData: ModuleState = {
52
- moduleName: nextModelu,
53
- initData,
54
- }
55
- this.changeMouleEvent(nextModelu, initData)
56
-
57
- this.historyPush(moduleData)
58
- console.log('next Log', this.stateMachineLog)
59
- console.log('next History', this.moduleStateHistory)
60
- }
61
-
62
- back = (initData: any = {}) => {
63
- if (this.moduleStateHistory.length <= 1) return
64
-
65
- const backModule = this.moduleStateHistory[1]
66
- this.changeMouleEvent(backModule.moduleName, {
67
- ...initData,
68
- ...backModule.initData,
69
- })
70
-
71
- this.moduleStateHistory.splice(0, 1)
72
- console.log('back Log', this.stateMachineLog)
73
- }
74
-
75
- // 业务终点 Log 发送
76
- end = () => {
77
- console.log('业务终点 Log', this.stateMachineLog)
78
-
79
- // TODO 请求
80
- }
81
-
82
- historyPush = (
83
- data: ModuleState,
84
- actionType: ActionType = ActionType.ChangeModule
85
- ) => {
86
- this.moduleStateHistory.unshift(data)
87
-
88
- this.stateMachineLog[this.order++] = {
89
- action: actionType,
90
- date: new Date().getTime(),
91
- dataSource: data,
92
- }
93
-
94
- if (this.moduleStateHistory.length > 10)
95
- this.moduleStateHistory.splice(10, this.moduleStateHistory.length - 10)
96
- }
97
-
98
- historyBack = (data: ModuleState) => {
99
- if (this.moduleStateHistory.length <= 1) return
100
-
101
- this.moduleStateHistory.splice(0, 1)
102
-
103
- this.stateMachineLog[this.order++] = {
104
- action: ActionType.Back,
105
- date: new Date().getTime(),
106
- dataSource: data,
107
- }
108
- }
109
-
110
- setConfig = (config: GuardConfig) => {
111
- this.config = config
112
- }
113
- }
114
-
115
- export const useHistoryHijack = (back?: () => void) => {
116
- const next = (state: any = {}) => {
117
- window?.history.pushState(state, '', window?.location.href)
118
- }
119
-
120
- useEffect(() => {
121
- const onPopstate = () => {
122
- back?.()
123
- }
124
-
125
- back && window?.addEventListener('popstate', onPopstate)
126
-
127
- return () => {
128
- back && window.removeEventListener('popstate', onPopstate)
129
- }
130
- }, [back])
131
-
132
- return [next]
133
- }