Answer the question
In order to leave comments, you need to log in
How to handle an error?
import { useState } from 'react';
import AuthService from '../http/auth';
export const useLogin = () => {
const [email, setEmail] = useState<string>('');
const [password, setPassword] = useState<string>('');
const [userAcc, setUserAcc] = useState<any>();
const userLogin = async () => {
try {
const response = await AuthService.login(email, password);
console.log(response);
// if (response.status === 404) {
// return alert('Не правльный логин или пароль!');
// }
localStorage.setItem('token', JSON.stringify(response.data.accessToken));
setUserAcc(response.data.user);
const dt = await AuthService.login(email, password);
} catch (error) {
console.log(error);
}
};
return { email, password, setEmail, setPassword, userLogin, userAcc };
};
alert
or somewhere else as in the above commented code!
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question