Files
logseq/packages/amplify/src/LSAuthenticator.tsx
Charlie 95c5cba9db Feat: The new login UI (#8865)
Built-in login UI instead of callback

---------

Co-authored-by: rcmerci <rcmerci@gmail.com>
Co-authored-by: Konstantinos Kaloutas <konstantinos@logseq.com>
Co-authored-by: Tienson Qin <tiensonqin@gmail.com>
2023-03-27 19:56:18 +08:00

60 lines
1.6 KiB
TypeScript

import { Authenticator, CheckboxField, useAuthenticator, AccountSettings } from '@aws-amplify/ui-react'
export function LSAuthenticator({ termsLink, children }: any) {
return (<div>
<Authenticator
formFields={{
signUp: {
email: { order: 1 },
username: { order: 2 },
password: { order: 3 },
confirm_password: { order: 4 },
}
}}
loginMechanisms={['username']}
socialProviders={['google']}
components={{
SignUp: {
FormFields() {
const { validationErrors } = useAuthenticator()
return (
<>
{/* Re-use default `Authenticator.SignUp.FormFields` */}
<Authenticator.SignUp.FormFields/>
{/* Append & require Terms & Conditions field to sign up */}
<CheckboxField
errorMessage={validationErrors.acknowledgement as string}
hasError={!!validationErrors.acknowledgement}
name="acknowledgement"
value="yes"
label={(<a href={termsLink}>I agree with the Terms & Conditions</a>)}
/>
</>
)
},
},
}}
services={{
async validateCustomSignUp(formData) {
if (!formData.acknowledgement) {
return {
acknowledgement: '',
}
}
}
}}
>
{children}
</Authenticator>
</div>)
}
export function LSAuthenticatorChangePassword(
{onSuccess, onError}
) {
return (
<AccountSettings.ChangePassword onSuccess={onSuccess} onError={onError}/>
)
}