Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion client/.env.sample
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
VITE_BASE_URL =

VITE_BASE_URL =

98 changes: 34 additions & 64 deletions client/src/components/Login/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ const Login = () => {
};

const loginUser = async (data) => {
const tostStyle= {
position: "top-center",
autoClose: 5000,
hideProgressBar: false,
closeOnClick: false,
pauseOnHover: false,
draggable: false,
progress: undefined,
theme: "light",
transition: Bounce,
};
setLoading(true);
axios
.post(`${import.meta.env.VITE_BASE_URL}/user/login`, data)
Expand All @@ -42,70 +53,29 @@ const Login = () => {
setloginError("");
setTimeout(() => {
navigate("/");
}, 1000);
toast.success("Logged in successfully!", {
position: "top-right",
autoClose: 5000,
hideProgressBar: false,
closeOnClick: false,
pauseOnHover: false,
draggable: false,
progress: undefined,
theme: "light",
transition: Bounce,
});
}
})
.catch((err) => {
if (err.response.data.message === "user not found") {
setloginError("User not found");
toast.warning("User not found!", {
position: "top-right",
autoClose: 5000,
hideProgressBar: false,
closeOnClick: false,
pauseOnHover: false,
draggable: false,
progress: undefined,
theme: "light",
transition: Bounce,
});
setLoading(false);
} else if (err.response.data.message === "Please verify email first") {
setloginError("Please verify email first");
localStorage.setItem("token", err.response.data.token);
setLoading(false);
navigate("/verifyotp");
} else if (err.response.data.message === "Invalid credentials") {
setloginError("Invalid Credentials");
toast.error("Invalid Credentials!", {
position: "top-right",
autoClose: 5000,
hideProgressBar: false,
closeOnClick: false,
pauseOnHover: false,
draggable: false,
progress: undefined,
theme: "light",
transition: Bounce,
});
setLoading(false);
} else {
setloginError("Something went wrong!");
toast.error("An error occurred!", {
position: "top-right",
autoClose: 5000,
hideProgressBar: false,
closeOnClick: false,
pauseOnHover: false,
draggable: false,
progress: undefined,
theme: "light",
transition: Bounce,
});
setLoading(false);
}
});

} else if (res.data.message === "user not found") {
setloginError("User not found");
toast.warning("User not found!",tostStyle);
} else if (res.data.message === "Invalid Credentials") {
setloginError("Invalid Credentials");
toast.error("Invalid credentials!",tostStyle);
} else if (res.data.message === "Unauthorized") {
setloginError("Invalid Credentials");
toast.error("Invalid credentials!",tostStyle);
}
else {
setloginError("Something went wrong!");
toast.error("An error occurred!",tostStyle);
}
});
setLoading(false);
} catch (error) {
console.error(error);
setLoading(false);
}


};

if (loading) {
Expand Down
4 changes: 3 additions & 1 deletion server/.env.sample
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
PORT =
MONGODB_URI =
SECRET =

ORIGIN =
APP_EMAIL =
APP_PASSWORD =
APP_PASSWORD =