amplify.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import './styles.css'
  2. import { Amplify, Auth, Hub, I18n } from 'aws-amplify'
  3. import { LSAuthenticator, LSAuthenticatorChangePassword } from './LSAuthenticator'
  4. import { dict } from 'aws-amplify-react/lib-esm/AmplifyI18n'
  5. // fix i18n
  6. dict.zh['Reset Password'] = '重置密码'
  7. dict.zh['Enter your username'] = '请输入用户名'
  8. dict.zh['Enter your email'] = '请输入邮箱'
  9. dict.zh['Enter your password'] = '请输入密码'
  10. dict.zh['Confirm Password'] = '确认密码'
  11. dict.zh['Please confirm your Password'] = '请确认密码'
  12. dict.zh['Incorrect username or password.'] = '用户名或者密码不正确。如果您的邮箱未验证,请尝试使用用户名(非邮箱)登录,以保证再次邮箱验证流程。'
  13. // @ts-ignore attach defaults
  14. dict.en = {
  15. 'Incorrect username or password.': 'Incorrect username or password! ' +
  16. 'For unconfirmed users, please input your username instead of Email to receive the code.'
  17. }
  18. const fixesMapping = {
  19. 'Sign Up': ['Sign up', 'Create Account'],
  20. 'Sign In': ['Sign in'],
  21. 'Sign Out': 'Sign out',
  22. 'Send Code': 'Send code',
  23. 'Forgot Password': ['Forgot your password?'],
  24. 'Enter your email': ['Enter your Email'],
  25. 'Enter your password': ['Enter your Password'],
  26. 'Enter your username': ['Enter your Username']
  27. }
  28. Object.keys(dict).forEach((k) => {
  29. const target = dict[k]
  30. Object.entries(fixesMapping).forEach(([k1, v1]) => {
  31. if (target?.hasOwnProperty(k1)) {
  32. const vs = Array.isArray(v1) ? v1 : [v1]
  33. vs.forEach(it => {
  34. target[it] = target[k1]
  35. })
  36. }
  37. })
  38. })
  39. I18n.putVocabularies(dict)
  40. function setupAuthConfigure(config) {
  41. const {
  42. region,
  43. userPoolId,
  44. userPoolWebClientId,
  45. identityPoolId,
  46. oauthDomain,
  47. oauthProviders
  48. } = config
  49. Amplify.configure({
  50. 'aws_project_region': region,
  51. 'aws_cognito_identity_pool_id': identityPoolId,
  52. 'aws_cognito_region': region,
  53. 'aws_user_pools_id': userPoolId,
  54. 'aws_user_pools_web_client_id': userPoolWebClientId,
  55. 'authenticationFlowType': 'USER_SRP_AUTH',
  56. 'oauth': {
  57. 'domain': oauthDomain,
  58. 'scope': [
  59. 'phone',
  60. 'email',
  61. 'openid',
  62. 'profile',
  63. 'aws.cognito.signin.user.admin'
  64. ],
  65. 'redirectSignIn': 'https://logseq.com/public/auth_callback.html',
  66. 'redirectSignOut': 'https://logseq.com/public/auth_callback.html',
  67. 'responseType': 'code'
  68. },
  69. 'federationTarget': 'COGNITO_USER_POOLS',
  70. 'aws_cognito_social_providers': oauthProviders || [
  71. 'GOOGLE'
  72. ],
  73. 'aws_cognito_signup_attributes': [
  74. 'EMAIL'
  75. ],
  76. 'aws_cognito_password_protection_settings': {
  77. 'passwordPolicyMinLength': 8,
  78. 'passwordPolicyCharacters': []
  79. },
  80. 'aws_cognito_verification_mechanisms': [
  81. 'EMAIL'
  82. ]
  83. })
  84. }
  85. //@ts-ignore
  86. window.LSAmplify = {
  87. setupAuthConfigure,
  88. LSAuthenticator, LSAuthenticatorChangePassword,
  89. Auth, Amplify, Hub, I18n
  90. }