Fix sign up error message not showing up

This commit is contained in:
powerwlsl 2022-08-06 04:28:54 +09:00
parent 87134e2990
commit 5cb03db3ea

View File

@ -34,8 +34,8 @@ const signup: SignupEndpoint['handlers']['signup'] = async ({
})
} catch (error) {
if (error instanceof BigcommerceApiError && error.status === 422) {
const hasEmailError = '0.email' in error.data?.errors
const hasEmailError = '.customer_create' in error.data?.errors
const hasPasswordError = '0.password' in error.data?.errors
// If there's an error with the email, it most likely means it's duplicated
if (hasEmailError) {
return res.status(400).json({
@ -48,6 +48,18 @@ const signup: SignupEndpoint['handlers']['signup'] = async ({
],
})
}
if (hasPasswordError) {
return res.status(400).json({
data: null,
errors: [
{
message: 'Passwords must be longer than 7 chars and include numbers',
code: 'duplicated_email',
},
],
})
}
}
throw error