LSAuthenticator.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { Authenticator, CheckboxField, useAuthenticator, AccountSettings } from '@aws-amplify/ui-react'
  2. export function LSAuthenticator({ termsLink, children }: any) {
  3. return (<div>
  4. <Authenticator
  5. formFields={{
  6. signUp: {
  7. email: { order: 1, isRequired: true },
  8. username: { order: 2, isRequired: true },
  9. password: { order: 3 },
  10. confirm_password: { order: 4 },
  11. },
  12. signIn: {
  13. username: {
  14. placeholder: 'Enter your Username or Email',
  15. label: 'Username or Email'
  16. }
  17. }
  18. }}
  19. loginMechanisms={['username']}
  20. socialProviders={['google']}
  21. components={{
  22. SignUp: {
  23. FormFields() {
  24. const { validationErrors } = useAuthenticator()
  25. return (
  26. <>
  27. {/* Re-use default `Authenticator.SignUp.FormFields` */}
  28. <Authenticator.SignUp.FormFields/>
  29. {/* Append & require Terms & Conditions field to sign up */}
  30. <CheckboxField
  31. errorMessage={validationErrors.acknowledgement as string}
  32. hasError={!!validationErrors.acknowledgement}
  33. name="acknowledgement"
  34. value="yes"
  35. label={(<a href={termsLink}>I agree with the Terms & Conditions</a>)}
  36. />
  37. </>
  38. )
  39. },
  40. },
  41. }}
  42. services={{
  43. async validateCustomSignUp(formData) {
  44. if (!formData.acknowledgement) {
  45. return {
  46. acknowledgement: '',
  47. }
  48. }
  49. }
  50. }}
  51. >
  52. {children}
  53. </Authenticator>
  54. </div>)
  55. }
  56. export function LSAuthenticatorChangePassword(
  57. {onSuccess, onError}
  58. ) {
  59. return (
  60. <AccountSettings.ChangePassword onSuccess={onSuccess} onError={onError}/>
  61. )
  62. }