const handleLogin = async (e: React.SyntheticEvent) => {
e.preventDefault();
try {
const body: LoginType = {
password: password,
account: account,
};
await loginApiCall(body)
.then((res) => {
if (res.status === 200) {
localStorage.setItem("relateToken", res.data.token);
console.log("user info ", res.data.user);
dispatch(setUserInfo(res.data.user));
authContext.setAuthState(true);
router.push("/");
}
})
.catch((err) => {
if (err.response.status === 400) {
toast.error(err.response.data.message);
} else {
toast.error("something went wrong try again later");
}
});
} catch (error) {
toast.error("something went wrong try again later");
console.log(error);
}
};