Commit 84a7c51d by jaymehta

.

1 parent b754dfc7
......@@ -10,7 +10,8 @@ import { useRouter } from "next/router";
import { signIn } from "next-auth/react";
import { toast } from "react-toastify";
import { Loader } from "react-bootstrap-typeahead";
import axios from "axios";
import qs from "qs";
const Login = props => {
const [loading, setLoading] = useState(false);
const loginValidationSchema = Yup.object().shape({
......@@ -34,6 +35,36 @@ const Login = props => {
validationSchema={loginValidationSchema}
// enableReinitialize={true}
onSubmit={async values => {
const userConfig = {
headers: {
"Content-Type": "application/json"
}
};
const query = {
filters: {
email: { $eq: values.email }
},
populate: ["role"],
// fields: ["email", "role"]
};
const queryString = qs.stringify(query, {
encodeValuesOnly: true
});
const existingUser = await axios.get(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/users?${queryString}`, userConfig);
// console.log("existingUser", existingUser);
if (props.type == "vendor") {
if (existingUser.data[0].role.name != "vendor") {
toast.error("This is vendor login, please use the login functionality in menu.");
return;
}
}
if (props.type == "user") {
if (existingUser.data[0].role.name != "endUser") {
toast.error("This is user login, please use the vendor login functionality in bottom menu.");
return;
}
}
// return;
setLoading(true);
console.log("login values", values);
const signInResponse = await signIn("credentials", {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!