@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,98 +0,0 @@
1
- import { Col, message, Row } from 'antd'
2
- import React, { FC } from 'react'
3
- import { EmailScene } from 'authing-js-sdk'
4
-
5
- import { SendCodeBtn } from './SendCodeBtn'
6
-
7
- import './style.less'
8
- import { useTranslation } from 'react-i18next'
9
- import { useAuthClient } from '../Guard/authClient'
10
- import { validate } from '../_utils'
11
- import Input, { InputProps } from 'antd/lib/input'
12
-
13
- export interface SendPhoneCodeProps extends InputProps {
14
- method: 'phone' | 'email'
15
- data: string
16
- form?: any
17
- onSendCodeBefore?: any // 点击的时候先做这个
18
- }
19
-
20
- export const SendCode: FC<SendPhoneCodeProps> = ({
21
- method,
22
- data,
23
- value,
24
- onChange,
25
- form,
26
- onSendCodeBefore,
27
- ...inputProps
28
- }) => {
29
- const { t } = useTranslation()
30
-
31
- const authClient = useAuthClient()
32
-
33
- const sendEmail = async (email: string) => {
34
- if (!email) {
35
- message.error(t('login.inputEmail'))
36
- return false
37
- }
38
- if (!validate('email', email)) {
39
- message.error(t('common.emailFormatError'))
40
- return false
41
- }
42
- try {
43
- await authClient.sendEmail(email, EmailScene.ResetPassword)
44
- // onSend?.()
45
- return true
46
- } catch (error) {
47
- // onError?.(error)
48
- return false
49
- }
50
- }
51
-
52
- const sendPhone = async (phone: string) => {
53
- try {
54
- await authClient.sendSmsCode(phone)
55
- return true
56
- } catch (error) {
57
- return false
58
- }
59
- }
60
- return (
61
- <>
62
- <Row justify="space-between" align="middle">
63
- <Col span={15} className="g2-send-code-input-col">
64
- <Input
65
- value={value}
66
- onChange={(e) => {
67
- let v = e.target.value
68
- if (v.length > 4) {
69
- return
70
- }
71
- onChange?.(e)
72
- }}
73
- // maxLength={4}
74
- type="number" // antd bug:如果 type===number 则 maxLength 不生效
75
- {...inputProps}
76
- />
77
- </Col>
78
- <Col offset={1} span={8}>
79
- <SendCodeBtn
80
- beforeSend={() => {
81
- return onSendCodeBefore()
82
- .then(async (b: any) => {
83
- let phoneData = form ? form.getFieldValue(method) : data
84
- return method === 'phone'
85
- ? await sendPhone(phoneData)
86
- : await sendEmail(phoneData)
87
- })
88
- .catch((e: any) => {
89
- // console.log('e', e)
90
- return false
91
- })
92
- }}
93
- />
94
- </Col>
95
- </Row>
96
- </>
97
- )
98
- }
@@ -1,31 +0,0 @@
1
- .authing-g2-send-code-btn {
2
- height: 46px;
3
- width: 100%;
4
- border: 1px solid #d4d6dc;
5
- border-radius: 4px;
6
- }
7
-
8
- .authing-g2-send-code-btn:hover {
9
- background: rgba(57, 106, 255, 0.1);
10
- }
11
-
12
- .authing-g2-send-code-btn:focus {
13
- outline: none;
14
- }
15
-
16
- .authing-g2-send-code-btn[disabled] {
17
- cursor: not-allowed;
18
- filter: opacity(0.5);
19
- }
20
-
21
- @media only screen and (max-width: 719px) {
22
- .authing-g2-send-code-btn {
23
- font-size: 14px;
24
- }
25
- }
26
-
27
- .g2-loading-btn-center {
28
- .authing-ant-btn-loading-icon .anticon {
29
- padding-right: 0;
30
- }
31
- }
@@ -1,27 +0,0 @@
1
- import React from 'react'
2
- import { ReactComponent as LoadShielding } from './loading.svg'
3
-
4
- interface IG2SpinProps {
5
- size?: number
6
- }
7
-
8
- export const ShieldSpin = (props: IG2SpinProps) => {
9
- let size = props.size ? props.size : 50
10
-
11
- return (
12
- <div
13
- style={{
14
- width: size,
15
- height: size,
16
- }}
17
- >
18
- <LoadShielding />
19
- </div>
20
- )
21
- }
22
-
23
- export const Spin = () => (
24
- <div className="g2-init-setting-loading">
25
- <ShieldSpin size={100} />
26
- </div>
27
- )
@@ -1,50 +0,0 @@
1
- import React, {
2
- forwardRef,
3
- useState,
4
- useImperativeHandle,
5
- useEffect,
6
- } from 'react'
7
- import { Button } from 'antd'
8
-
9
- interface SubmitButtonProps {
10
- text?: string
11
- className?: string
12
- onClick?: any
13
- }
14
- const SubmitButton = (props: SubmitButtonProps, ref: any) => {
15
- let [spin, setSpin] = useState(false) // spin 状态需要手动设置关闭
16
- let [shaking, setShaking] = useState(false) // 抖动状态会自动关闭
17
-
18
- useEffect(() => {
19
- if (shaking === true) {
20
- setTimeout(() => {
21
- setShaking(false)
22
- }, 1000)
23
- }
24
- }, [shaking])
25
-
26
- useImperativeHandle(ref, () => ({
27
- onError: (text?: string) => {
28
- setShaking(true)
29
- },
30
- onSpin: (sp: boolean) => {
31
- setSpin(sp)
32
- },
33
- }))
34
-
35
- let propsCls = props.className ? props.className : ''
36
- let shakingCls = shaking ? 'shaking' : ''
37
- return (
38
- <Button
39
- size="large"
40
- type="primary"
41
- htmlType="submit"
42
- loading={spin}
43
- onClick={props.onClick ? props.onClick : () => {}}
44
- className={`authing-g2-submit-button ${propsCls} ${shakingCls}`}
45
- >
46
- {props.text}
47
- </Button>
48
- )
49
- }
50
- export default forwardRef(SubmitButton)
@@ -1,61 +0,0 @@
1
- import { AuthenticationClient, CommonMessage } from 'authing-js-sdk'
2
- import { Lang } from 'authing-js-sdk/build/main/types'
3
- import { ApplicationConfig } from '../AuthingGuard/api'
4
- import { GuardModuleType } from '../Guard/module'
5
-
6
- export enum GuardMode {
7
- Modal = 'modal',
8
- Normal = 'normal',
9
- }
10
-
11
- export enum GuardScenes {
12
- Login = 'login',
13
- Register = 'register',
14
- }
15
- export interface IG2FCProps extends IG2Events {
16
- appId: string
17
- config?: Partial<IG2Config>
18
- }
19
-
20
- export interface IG2FCViewProps extends IG2FCProps {
21
- config: IG2Config
22
- }
23
-
24
- export interface IG2Config {
25
- title: string
26
- logo: string
27
- lang: Lang
28
- langRange: Lang[]
29
- host: string
30
- mode: GuardMode
31
- clickCloseable: boolean
32
- escCloseable: boolean
33
- userpool?: string
34
- contentCss?: string
35
- target?: HTMLElement | string
36
- __appHost__?: string
37
- __publicConfig__?: ApplicationConfig
38
- }
39
-
40
- const defaultG2Config: IG2Config = {
41
- lang: 'zh-CN',
42
- langRange: ['zh-CN', 'en-US'],
43
- title: 'Authing',
44
- escCloseable: true,
45
- clickCloseable: true,
46
- mode: GuardMode.Normal,
47
- host: 'https://core.authing.cn',
48
- logo:
49
- 'https://files.authing.co/user-contents/photos/0a4c99ff-b8ce-4030-aaaf-584c807cb21c.png',
50
- }
51
-
52
- export interface IG2Events {
53
- onLoad?: (authClient: AuthenticationClient) => void
54
- onLoadError?: (error: CommonMessage) => void
55
- onClose?: () => void
56
- onLangChange?: (lang: Lang) => void
57
- // __codePaser?: (code: number) => Function
58
- __changeModule?: (moduleName: GuardModuleType, initData: any) => void
59
- }
60
-
61
- export const getDefaultG2Config = (): IG2Config => defaultG2Config
@@ -1,76 +0,0 @@
1
- import { Divider, Input } from 'antd'
2
- import React, { FC, Fragment, useRef } from 'react'
3
-
4
- import './style.less'
5
-
6
- interface VerifyCodeInputProps extends React.HTMLAttributes<HTMLDivElement> {
7
- verifyCode: string[]
8
- setVerifyCode: (code: string[]) => void
9
- length?: number
10
- onEnter?: Function
11
- }
12
-
13
- export const VerifyCodeInput: FC<VerifyCodeInputProps> = ({
14
- verifyCode,
15
- setVerifyCode,
16
- length = 6,
17
- onEnter,
18
- }) => {
19
- const inputRef = useRef<any[]>([])
20
-
21
- const handleChange = (val: string | undefined = '', index: number) => {
22
- const num = parseInt(val)
23
- if (isNaN(num)) {
24
- val = ''
25
- } else {
26
- val = String(num)
27
- }
28
- const codes = [...verifyCode]
29
- codes[index] = val.split('').slice(-1)[0] || ''
30
- setVerifyCode(codes)
31
-
32
- if (val && inputRef.current[index + 1]) {
33
- inputRef.current[index + 1].focus()
34
- }
35
- }
36
-
37
- const handleKeyDown = (evt: any, index: number) => {
38
- const currentVal = verifyCode[index]
39
-
40
- switch (evt.keyCode) {
41
- case 8:
42
- if (!currentVal && inputRef.current[index - 1]) {
43
- handleChange('', index - 1)
44
- inputRef.current[index - 1].focus()
45
- }
46
- break
47
-
48
- case 13:
49
- onEnter?.()
50
- break
51
- default:
52
- break
53
- }
54
- }
55
-
56
- return (
57
- <div className="authing-code-input">
58
- {new Array(length).fill(0).map((_, index) => (
59
- <Fragment key={index}>
60
- <Input
61
- ref={(el) => (inputRef.current[index] = el)}
62
- className="authing-code-input-item"
63
- size="large"
64
- autoFocus={index === 0}
65
- onKeyDown={(evt) => handleKeyDown(evt, index)}
66
- value={verifyCode[index]}
67
- onChange={(evt) => handleChange(evt.target.value, index)}
68
- />
69
- {index === Math.floor(length / 2 - 1) && (
70
- <Divider className="authing-code-input-divider" />
71
- )}
72
- </Fragment>
73
- ))}
74
- </div>
75
- )
76
- }
@@ -1,24 +0,0 @@
1
- .authing-code-input-item {
2
- text-align: center;
3
- width: 40px;
4
- min-width: 40px;
5
- min-height: 40px;
6
- height: 40px;
7
- line-height: 40px;
8
- &:not(:first-child) {
9
- margin-left: 18px;
10
- }
11
- input {
12
- text-align: center;
13
- }
14
- }
15
- .authing-code-input-divider {
16
- width: 14px;
17
- min-width: 14px;
18
- max-width: 14px;
19
- margin-left: 18px;
20
- }
21
- .authing-code-input {
22
- display: flex;
23
- align-items: center;
24
- }
@@ -1,8 +0,0 @@
1
- export enum ErrorCode {
2
- OTP_MFA_CODE = 1635,
3
- APP_MFA_CODE = 1636,
4
- INPUT_CAPTCHACODE = 2000,
5
- USER_EXISTENCE = 2026,
6
- LOGIN_INVALID = 2021,
7
- PASSWORD_ERROR = 2333,
8
- }
@@ -1,27 +0,0 @@
1
- import { i18n } from './locales'
2
-
3
- // https://juejin.im/post/6844903857290477582
4
- export const copyToClipboard = (str: string) => {
5
- const el = document.createElement('textarea') // 创建一个 <textarea> 元素
6
- el.value = str // 设置它的值为你想复制的字符串
7
- el.setAttribute('readonly', '') // 设置为只读以防止干扰
8
- el.style.position = 'absolute'
9
- el.style.left = '-9999px' // 移出屏幕外以使其不可见
10
- document.body.appendChild(el) // 插入 <textarea> 元素到 HTML 文档中
11
- try {
12
- const selected =
13
- document.getSelection()!.rangeCount > 0 // 检查是否之前曾选中过内容
14
- ? document.getSelection()!.getRangeAt(0) // 如果找到,则保存选中
15
- : false // 标记为 false 以表示不存在之前选中的内容
16
- el.select() // 选中 <textarea> 的内容
17
- document.execCommand('copy') // 复制 - 仅当作为用户操作的响应结果时才可以工作(比如,点击事件)
18
- document.body.removeChild(el) // 移除 <textarea> 元素
19
- if (selected) {
20
- // 如果在复制前已存在选中的内容
21
- document.getSelection()!.removeAllRanges() // 取消 HTML 文档中所有的选中部分
22
- document.getSelection()!.addRange(selected) // 恢复原来的选中
23
- }
24
- } catch (e) {
25
- console.warn(i18n.t('common.copyFailed'))
26
- }
27
- }
@@ -1,123 +0,0 @@
1
- import { LoginMethods, RegisterMethods } from 'authing-js-sdk'
2
- import { IG2Config } from '../Type'
3
- import { ApplicationConfig } from '../AuthingGuard/api'
4
- import { LoginConfig } from '../Login/props'
5
- import { RegisterConfig } from '../Register/props'
6
- import { assembledAppHost } from '.'
7
- import { GuardHttp } from './guradHttp'
8
- import { AuthingResponse } from './http'
9
- import { GuardComponentConifg } from '../Guard/config'
10
-
11
- export interface GuardConfig extends RegisterConfig, LoginConfig {}
12
-
13
- let publicConfigMap: Record<string, ApplicationConfig> = {}
14
-
15
- const getPublicConfig = (appId: string) => publicConfigMap?.[appId]
16
-
17
- const setPublicConfig = (appId: string, config: ApplicationConfig) =>
18
- (publicConfigMap[appId] = config)
19
-
20
- export const initConfig = async (
21
- appId: string,
22
- config: Partial<IG2Config>,
23
- defaultConfig: IG2Config
24
- ): Promise<{ config: GuardConfig; publicConfig: ApplicationConfig }> => {
25
- if (!getPublicConfig(appId))
26
- await requestPublicConfig(appId, config.host ?? defaultConfig.host)
27
- const mergedConfig = mergeConfig(
28
- config,
29
- defaultConfig,
30
- getPublicConfig(appId)
31
- )
32
-
33
- return {
34
- config: {
35
- ...mergedConfig,
36
- __publicConfig__: getPublicConfig(appId),
37
- __appHost__: assembledAppHost(
38
- getPublicConfig(appId).identifier,
39
- mergedConfig?.host!
40
- ),
41
- },
42
- publicConfig: getPublicConfig(appId),
43
- }
44
- }
45
-
46
- const mergeConfig = (
47
- config: GuardComponentConifg,
48
- defaultConfig: IG2Config,
49
- publicConfig: ApplicationConfig
50
- ): GuardConfig => {
51
- const mergedPublicConfig: GuardConfig = {
52
- ...defaultConfig,
53
- ...config,
54
- title: config.title ?? publicConfig.name,
55
- logo: config.logo ?? publicConfig.logo,
56
- loginMethods:
57
- config?.loginMethods ??
58
- (publicConfig.loginTabs?.list as LoginMethods[]) ??
59
- [],
60
- passwordLoginMethods:
61
- config?.passwordLoginMethods ??
62
- publicConfig.passwordTabConfig?.enabledLoginMethods ??
63
- [],
64
- // 默认登录方式
65
- defaultLoginMethod:
66
- config.defaultLoginMethod ??
67
- (publicConfig.loginTabs.default as LoginMethods),
68
- // 禁止重制密码
69
- disableResetPwd: !!(
70
- config.disableResetPwd ??
71
- !publicConfig.ssoPageComponentDisplay?.registerBtn
72
- ),
73
- // 是否自动注册
74
- autoRegister:
75
- config.autoRegister ??
76
- publicConfig.ssoPageComponentDisplay.autoRegisterThenLoginHintInfo,
77
- registerMethods:
78
- config.registerMethods ??
79
- (publicConfig.registerTabs?.list as RegisterMethods[]),
80
- defaultRegisterMethod:
81
- config.defaultRegisterMethod ??
82
- (publicConfig.registerTabs.default as RegisterMethods),
83
- // 禁止注册
84
- disableRegister: !!(
85
- config.disableRegister ??
86
- !publicConfig.ssoPageComponentDisplay.registerBtn
87
- ),
88
- // publicKey
89
- publicKey: config.publicKey ?? publicConfig.publicKey,
90
- // 注册协议
91
- agreementEnabled: config.agreementEnabled ?? publicConfig.agreementEnabled,
92
- agreements: config.agreements ?? publicConfig.agreements,
93
- contentCss: config.contentCss ?? publicConfig.css,
94
- }
95
-
96
- return mergedPublicConfig
97
- }
98
-
99
- const requestPublicConfig = async (
100
- appId: string,
101
- host: string
102
- ): Promise<ApplicationConfig> => {
103
- let res: AuthingResponse<ApplicationConfig>
104
-
105
- const guardHttp = new GuardHttp(host)
106
- guardHttp.setAppId(appId)
107
-
108
- try {
109
- res = await guardHttp.get<ApplicationConfig>(
110
- `/api/v2/applications/${appId}/public-config`
111
- )
112
- } catch (error) {
113
- console.error('Please check your config or network')
114
- throw new Error('Please check your config or network')
115
- }
116
-
117
- if (res.code !== 200 || !res.data)
118
- throw new Error(res?.message ?? 'Please check your config')
119
-
120
- setPublicConfig(appId, res.data)
121
-
122
- return getPublicConfig(appId)
123
- }
@@ -1,93 +0,0 @@
1
- import packageConfig from '../../package.json'
2
- import { requestClient } from './http'
3
-
4
- let httpClient: GuardHttp
5
-
6
- export class GuardHttp {
7
- private requestClient: any
8
- private headers: Record<string, string> = {
9
- 'x-authing-userpool-id': '',
10
- 'x-authing-app-id': '',
11
- 'x-authing-sdk-version': packageConfig.version,
12
- 'x-authing-request-from': `Guard-${packageConfig.framework}@${packageConfig.version}`,
13
- }
14
-
15
- constructor(baseUrl: string) {
16
- this.getRequestClient().setBaseUrl(baseUrl)
17
- }
18
-
19
- private getRequestClient() {
20
- if (!this.requestClient) {
21
- this.requestClient = requestClient
22
- }
23
-
24
- return this.requestClient
25
- }
26
-
27
- setUserpoolId(userpoolId: string) {
28
- this.headers['x-authing-userpool-id'] = userpoolId
29
- }
30
-
31
- setAppId(appId: string) {
32
- this.headers['x-authing-app-id'] = appId
33
- }
34
-
35
- public getHeaders = () => this.headers
36
-
37
- public get = async <T>(
38
- path: string,
39
- query: Record<string, any> = {},
40
- config?: RequestInit
41
- ) =>
42
- await requestClient.get<T>(path, query, {
43
- ...config,
44
- headers: { ...this.headers, ...config?.headers },
45
- })
46
-
47
- public post = async <T>(
48
- path: string,
49
- data: any,
50
- config?: {
51
- headers: any
52
- }
53
- ) =>
54
- await requestClient.post<T>(path, data, {
55
- headers: {
56
- ...this.headers,
57
- ...config?.headers,
58
- },
59
- })
60
-
61
- public postForm = async <T>(
62
- path: string,
63
- formData: any,
64
- config?: {
65
- headers: any
66
- }
67
- ) =>
68
- await requestClient.postForm<T>(path, formData, {
69
- headers: {
70
- ...this.headers,
71
- ...config?.headers,
72
- },
73
- })
74
- }
75
-
76
- export const initGuardHttp = (baseUrl: string) => {
77
- if (!httpClient) {
78
- const guardHttp = new GuardHttp(baseUrl)
79
- httpClient = guardHttp
80
- }
81
-
82
- return httpClient
83
- }
84
-
85
- export const getGuardHttp = () => {
86
- if (!httpClient) {
87
- throw new Error('Please initialize Http Client')
88
- }
89
-
90
- return httpClient
91
- }
92
-
93
- export const useGuardHttp = () => getGuardHttp()
@@ -1,56 +0,0 @@
1
- import { useRef, useCallback } from 'react'
2
- import { GuardModuleType } from '../../Guard/module'
3
- import { useModule } from '../../context/module/context'
4
-
5
- export const useChangeModule = () => {
6
- const { module, changeModule, setInitData } = useModule()
7
-
8
- const nextModule = (nextModuleType: GuardModuleType, nextData?: any) => {
9
- if (nextModuleType !== module) changeModule(nextModuleType)
10
-
11
- setInitData(nextData ?? {})
12
- }
13
-
14
- return nextModule
15
- }
16
-
17
- let thisAppId: string = ''
18
-
19
- export const useAppId = (appId?: string) => {
20
- if (appId) {
21
- thisAppId = appId
22
- }
23
-
24
- return thisAppId
25
- }
26
-
27
- export const useDebounce = (
28
- // 回调函数
29
- fn: any,
30
- // 延迟时间
31
- delay: number
32
- ) => {
33
- const timer = useRef<{ time: any }>({ time: null })
34
- const errorBody = useRef<{ body: any }>({ body: null })
35
- return useCallback(
36
- (...args: any[]) => {
37
- if (timer.current.time) {
38
- clearTimeout(timer.current.time)
39
- timer.current.time = null
40
- }
41
- timer.current.time = setTimeout(() => {
42
- // fn.apply(this, args);
43
- const res = fn(...args)
44
- timer.current.time = null
45
- errorBody.current.body = res
46
- }, delay)
47
- if (errorBody.current.body) {
48
- return Promise.reject(errorBody.current.body)
49
- } else {
50
- return Promise.resolve()
51
- }
52
- },
53
- // eslint-disable-next-line react-hooks/exhaustive-deps
54
- [timer.current, delay]
55
- )
56
- }