@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,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
- }