Skip to content

Commit

Permalink
fix: fix recover password
Browse files Browse the repository at this point in the history
  • Loading branch information
Matheusafonsouza committed Dec 9, 2024
1 parent 42e897d commit 681a002
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/hooks/useApi/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const useApi = () => {
recoverPassword: (email: string): Promise<{ data: any }> => {
return new Promise((resolve) => {
api
.post(`/auth/recover-password/${email}`)
.post(`/auth/recover-password`, { email })
.then((res) => resolve(res))
.catch((err) => resolve(getDefaultErrorUseAPIMessage(err)));
});
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {

async function recoverPassword(email: string): Promise<boolean> {
const { data } = await authRecoverPassword(email);
if (data.id) {
if (data.success) {
toaster.create({
title: 'E-mail enviado para recuperação de senha!',
type: 'success',
Expand All @@ -110,7 +110,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {

async function changePassword(password: string, token: string): Promise<boolean> {
const { data } = await authChangePassword(password, token);
if (data.id) {
if (data.success) {
toaster.create({
title: 'Senha alterada com sucesso! Você será redirecionado para o login...',
type: 'success',
Expand Down
4 changes: 3 additions & 1 deletion src/pages/ChangePassword/ChangePasswordForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useForm } from 'react-hook-form';
import { Button } from '../../../components/ui/button';
import { Field } from '../../../components/ui/field';
import { PasswordInput } from '../../../components/ui/password-input';
import { useLocation } from 'react-router';
import { useLocation, useNavigate } from 'react-router';

interface FormValues {
password: string;
Expand All @@ -18,6 +18,7 @@ function useQuery() {

function ChangePasswordForm() {
const query = useQuery();
const navigate = useNavigate();
const [loading, setLoading] = useState(false);

const token = query.get('token');
Expand All @@ -35,6 +36,7 @@ function ChangePasswordForm() {
setLoading(true);
await changePassword(data.password, token);
setLoading(false);
navigate('/login')
})

return (
Expand Down
12 changes: 10 additions & 2 deletions src/pages/SignIn/SignInForm/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from 'react';
import { useAuth } from '../../../hooks/useAuth';
import { useNavigate } from 'react-router';
import { Input, Stack } from '@chakra-ui/react';
import { Link, useNavigate } from 'react-router';
import { Input, Stack, Link as ChakraLink, Text } from '@chakra-ui/react';
import { useForm } from 'react-hook-form';
import { PasswordInput } from '../../../components/ui/password-input';
import { Button } from '../../../components/ui/button';
Expand Down Expand Up @@ -62,6 +62,14 @@ function SignInForm() {
{...register('password', { required: "Campo obrigatório." })}
/>
</Field>
<Stack gap={'25px'} width={'100%'}>
<Text
textAlign={'center'}
color={'blue.100'}
>
Não lembra sua senha? <ChakraLink color={'green.100'}><Link to='/recuperar-senha'>Recupere ela aqui</Link></ChakraLink>
</Text>
</Stack>
</Stack>
<Button
loading={loading}
Expand Down

0 comments on commit 681a002

Please sign in to comment.