From 8ef14cbbbcb8a8125da6b31b611e9a01580c3a0b Mon Sep 17 00:00:00 2001 From: "Embruch, Gerd" <gerd.embruch@uni-hamburg.de> Date: Fri, 2 Aug 2024 13:45:13 +0200 Subject: [PATCH] fixed password reset --- src/contexts/Auth/AuthState.jsx | 7 +------ src/pages/User/ResetPassword.jsx | 12 ++++++------ src/routes/Sitemap.jsx | 16 ---------------- 3 files changed, 7 insertions(+), 28 deletions(-) diff --git a/src/contexts/Auth/AuthState.jsx b/src/contexts/Auth/AuthState.jsx index 2777916..64a32e5 100755 --- a/src/contexts/Auth/AuthState.jsx +++ b/src/contexts/Auth/AuthState.jsx @@ -56,13 +56,9 @@ function AuthState({ children }) { // ### REQUEST PASSWORD RESET function requestPasswordReset(email) { - return api.post('/users/requestpasswordreset', { email }); + return api.post('/auth/password-reset', { email }); } - // ### REQUEST PASSWORD RESET - function requestEmailReset(email) { - return api.post('/users/requestemailchange', { email }); - } // ### RETURN return ( @@ -73,7 +69,6 @@ function AuthState({ children }) { logout, requestVerificationToken, requestPasswordReset, - requestEmailReset, USER_ACTIONS, dispatchCurrentUser }}> diff --git a/src/pages/User/ResetPassword.jsx b/src/pages/User/ResetPassword.jsx index 29d0067..72865b3 100644 --- a/src/pages/User/ResetPassword.jsx +++ b/src/pages/User/ResetPassword.jsx @@ -18,13 +18,14 @@ function ResetPasswordForm() { // VALIDATION SCHEMA // ################################# const schema = z.object({ + token: z.string().min(1), password: z.string().refine((val) => val && isStrongPassword(val), { message: 'This field must be min 6 characters long and contain uppercase, lowercase, number, specialchar.', }), - passwordConfirm: z.string(), - }).refine((data) => data.password === data.passwordConfirm, { + confirmPassword: z.string(), + }).refine((data) => data.password === data.confirmPassword, { message: "Passwords don't match", - path: ["passwordConfirm"], + path: ["confirmPassword"], }); // ################################# @@ -54,11 +55,10 @@ function ResetPasswordForm() { // ### HANDLE SUBMITTING FORM async function handleSendForm(inputs) { - // TRY UPDATE try { // send data - const result = await api.post(`/users/confirmpasswordreset`, inputs); + const result = await api.patch(`/auth/password-reset`, inputs); await logout(); redirect('/login'); // set flash message @@ -83,7 +83,7 @@ function ResetPasswordForm() { <form onSubmit={methods.handleSubmit(handleSendForm)}> <Input name='token' type='text' title='confirm token' className='h-16' /> <Input name='password' type='password' title='new password' className='h-16' autoFocus={true} /> - <Input name='passwordConfirm' type='password' title='confirm password' className='h-16' /> + <Input name='confirmPassword' type='password' title='confirm password' className='h-16' /> <Submit value='Reset' /> </form> diff --git a/src/routes/Sitemap.jsx b/src/routes/Sitemap.jsx index 3b99f04..17567ff 100644 --- a/src/routes/Sitemap.jsx +++ b/src/routes/Sitemap.jsx @@ -27,22 +27,6 @@ export const sitemap = [{ ] }, - // REQUEST CHANGE EMAIL ADDRESS - { - title: 'Change eMail', - path: '/change_email', - handle: { crumb: () => <Link to="/change_email">Change eMail</Link> }, - children: [ - { index: true, element: loadComponent('User/RequestChangeMail') }, - // CHANGE EMAIL ADDRESS - { - title: 'Change eMail', - path: ':token', - hidden: true, - element: loadComponent('User/ChangeMail') - } - ] - }, // LOGOUT { title: 'Logout', -- GitLab