diff --git a/client/src/components/Authentication.js b/client/src/components/Authentication.js index cc2871888..af80309a5 100644 --- a/client/src/components/Authentication.js +++ b/client/src/components/Authentication.js @@ -7,10 +7,10 @@ export default function({ isAuthenticated =false, ...rest }) { const to = {pathname: '/dashboard/homepage'}; return ( - - - { (isAuthenticated) ? - () : ( + + { (isAuthenticated) ? + () : ( +
-
) - } -
-
+ + + ) + } + ); } \ No newline at end of file diff --git a/client/src/components/PrivateRoute.js b/client/src/components/PrivateRoute.js index 5df23cc59..6793eee9d 100644 --- a/client/src/components/PrivateRoute.js +++ b/client/src/components/PrivateRoute.js @@ -1,5 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; +import BodyClassName from 'react-body-classname'; import { Route, Redirect } from 'react-router-dom'; const propTypes = { @@ -13,19 +14,21 @@ function PrivateRoute({ ...rest }) { return ( - - isAuthenticated ? () : - ( - - )} - /> + + + isAuthenticated ? () : + ( + + )} + /> + ); } diff --git a/client/src/containers/Authentication/Register.js b/client/src/containers/Authentication/Register.js index c2809ec35..868e30b5b 100644 --- a/client/src/containers/Authentication/Register.js +++ b/client/src/containers/Authentication/Register.js @@ -63,7 +63,7 @@ function Register({ ...initialValues, country: 'libya' }, - onSubmit: (values, { setSubmitting }) => { + onSubmit: (values, { setSubmitting, setErrors }) => { requestRegister(values) .then((response) => { AppToaster.show({ @@ -72,7 +72,17 @@ function Register({ setSubmitting(false); history.push('/auth/login'); }) - .catch((error) => { + .catch((errors) => { + if (errors.some(e => e.type === 'PHONE_NUMBER_EXISTS')) { + setErrors({ + phone_number: 'The phone number is already used in another account.' + }); + } + if (errors.some(e => e.type === 'EMAIL_EXISTS')) { + setErrors({ + email: 'The email is already used in another account.' + }); + } setSubmitting(false); }); }, diff --git a/server/src/http/controllers/Authentication.js b/server/src/http/controllers/Authentication.js index 414e438fd..53590c69a 100644 --- a/server/src/http/controllers/Authentication.js +++ b/server/src/http/controllers/Authentication.js @@ -129,15 +129,16 @@ export default { .orWhere('phone_number', form.phone_number) .first(); + const errorReasons = []; + if (user && user.phoneNumber === form.phone_number) { - return res.boom.badRequest(null, { - errors: [{ type: 'PHONE_NUMBER_EXISTS', code: 100 }], - }); + errorReasons.push({ type: 'PHONE_NUMBER_EXISTS', code: 100 }); } if (user && user.email === form.email) { - return res.boom.badRequest(null, { - errors: [{ type: 'EMAIL_EXISTS', code: 200 }], - }); + errorReasons.push({ type: 'EMAIL_EXISTS', code: 200 }); + } + if (errorReasons.length > 0) { + return res.status(400).send({ errors: errorReasons }); } const organizationId = uniqid(); const tenantOrganization = await Tenant.query().insert({