From 4fcd3104df1ffbda743b6de7a3ee8bf6721496da Mon Sep 17 00:00:00 2001 From: victorAnumudu Date: Sat, 15 Apr 2023 07:29:03 +0100 Subject: [PATCH] login layout reverted and login function cleaned up --- .../auth/components/ForgotPassword.tsx | 6 ++++++ src/app/modules/auth/components/Login.tsx | 20 ++++++++++++++----- .../modules/auth/components/Registration.tsx | 7 ++++++- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/app/modules/auth/components/ForgotPassword.tsx b/src/app/modules/auth/components/ForgotPassword.tsx index 4bb8dce..3945f93 100644 --- a/src/app/modules/auth/components/ForgotPassword.tsx +++ b/src/app/modules/auth/components/ForgotPassword.tsx @@ -50,6 +50,12 @@ export function ForgotPassword() { id='kt_login_password_reset_form' onSubmit={formik.handleSubmit} > + {/* begin::Heading */} +
+ {/*

Sign In

*/} + Float Mobility +
+ {/* begin::Heading */}
{/* begin::Link */}
diff --git a/src/app/modules/auth/components/Login.tsx b/src/app/modules/auth/components/Login.tsx index 16b701c..ff2e053 100644 --- a/src/app/modules/auth/components/Login.tsx +++ b/src/app/modules/auth/components/Login.tsx @@ -8,8 +8,6 @@ import {getUserByToken, login} from '../core/_requests' import {toAbsoluteUrl} from '../../../../_metronic/helpers' import {useAuth} from '../core/Auth' -import {useNavigate} from 'react-router-dom' - const loginSchema = Yup.object().shape({ email: Yup.string() .email('Wrong email format') @@ -34,7 +32,6 @@ const initialValues = { */ export function Login() { - const navigate = useNavigate() const [loading, setLoading] = useState(false) const {saveAuth, setCurrentUser} = useAuth() @@ -42,14 +39,22 @@ export function Login() { initialValues, validationSchema: loginSchema, onSubmit: async (values, {setStatus, setSubmitting}) => { + setStatus('') setLoading(true) try { const {data: auth} = await login(values.email, values.password) - saveAuth(auth) // const {data: user} = await getUserByToken(auth.session_token) // setCurrentUser(user) + if(auth.status <= 0){ // checking if request is not successful + setStatus('The login details are incorrect') + setSubmitting(false) + setLoading(false) + console.log(auth) //remove later + return + } + saveAuth(auth) setCurrentUser(auth.profile) - navigate('/dashboard') + console.log(auth) //remove later } catch (error) { console.error(error) saveAuth(undefined) @@ -68,6 +73,11 @@ export function Login() { id='kt_login_signin_form' > {/* begin::Heading */} +
+ {/*

Sign In

*/} + Float Mobility +
+ {/* begin::Heading */} {/* begin::Login options */}
diff --git a/src/app/modules/auth/components/Registration.tsx b/src/app/modules/auth/components/Registration.tsx index 1f50932..715433b 100644 --- a/src/app/modules/auth/components/Registration.tsx +++ b/src/app/modules/auth/components/Registration.tsx @@ -86,7 +86,12 @@ export function Registration() { id='kt_login_signup_form' onSubmit={formik.handleSubmit} > - + {/* begin::Heading */} +
+ {/*

Sign In

*/} + Float Mobility +
+ {/* begin::Heading */} {/* begin::Login options */}
{/* begin::Col */}