Added login operation

This commit is contained in:
Luis Alvarez
2020-10-20 12:51:35 -05:00
parent c9ee2af3e5
commit 7db006f64a
3 changed files with 57 additions and 5 deletions

View File

@@ -17,8 +17,10 @@ const createCustomer: CustomersHandlers['createCustomer'] = async ({
// Passwords must be at least 7 characters and contain both alphabetic
// and numeric characters.
let result: { data?: any } = {}
try {
const { data } = await config.storeApiFetch('/v3/customers', {
result = await config.storeApiFetch('/v3/customers', {
method: 'POST',
body: JSON.stringify([
{
@@ -31,8 +33,6 @@ const createCustomer: CustomersHandlers['createCustomer'] = async ({
},
]),
})
res.status(200).json({ data })
} catch (error) {
if (error instanceof BigcommerceApiError && error.status === 422) {
const hasEmailError = '0.email' in error.data?.errors
@@ -53,6 +53,8 @@ const createCustomer: CustomersHandlers['createCustomer'] = async ({
throw error
}
res.status(200).json({ data: result.data ?? null })
}
export default createCustomer