handle-auth-errors

This commit is contained in:
Untone 2024-05-19 01:14:28 +03:00 committed by dog
parent 7e2f2d5192
commit 8a36b21e6e

View File

@ -96,27 +96,30 @@ export const LoginForm = () => {
try { try {
const { errors } = await signIn({ email: email(), password: password() }) const { errors } = await signIn({ email: email(), password: password() })
if (errors?.length > 0) { if (errors?.length > 0) {
console.error('[signIn errors]', errors) console.warn('[signIn] errors: ', errors)
if (errors.some((error) => error.message.includes('user has not signed up email & password'))) { let msg = ''
setValidationErrors((prev) => ({ if (errors.some((error) => error.message === 'user has not signed up email & password')) {
...prev, const password = t('Something went wrong, check email and password')
password: t('Something went wrong, check email and password'), setValidationErrors((prev) => ({ ...prev, password }))
})) } else if (errors.some((error) => error.message === 'user not found')) {
} else if (errors.some((error) => error.message.includes('user not found'))) { msg = t('User was not found')
setSubmitError(t('User was not found')) } else if (errors.some((error) => error.message === 'email not verified')) {
} else if (errors.some((error) => error.message.includes('email not verified'))) { msg = t('This email is not verified')
} else {
msg = t('Error', errors[0].message)
}
msg &&
setSubmitError( setSubmitError(
<div class={styles.info}> <div class={styles.info}>
{t('This email is not verified')} {msg}
{'. '} {'. '}
<span class={'link'} onClick={handleSendLinkAgainClick}> <span class={'link'} onClick={handleSendLinkAgainClick}>
{t('Send link again')} {t('Send link again')}
</span> </span>
</div>, </div>,
) )
} else {
setSubmitError(t('Error', errors[0].message))
}
return return
} }
hideModal() hideModal()