'register-validations-updated'

parent fc961257
...@@ -81,14 +81,14 @@ app.post('/registeruser', checkUserIdExists, (req, res) => { ...@@ -81,14 +81,14 @@ app.post('/registeruser', checkUserIdExists, (req, res) => {
}); });
// Get Users endpoint // Get Users endpoint
// app.get('/users', (req, res) => { app.get('/users', (req, res) => {
// // db.collection('users').find({}, { projection: { _id: false, userId: true, password: true } }).toArray() // db.collection('users').find({}, { projection: { _id: false, userId: true, password: true } }).toArray()
// db.collection('users').find({}, { projection: { _id: false } }).toArray() db.collection('users').find({}, { projection: { _id: false } }).toArray()
// .then(result => { .then(result => {
// res.send(result); res.send(result);
// }) })
// .catch(error => res.status(500).send(error)); .catch(error => res.status(500).send(error));
// }); });
//login api //login api
app.post('/login', async (req, res) => { app.post('/login', async (req, res) => {
......
...@@ -22,16 +22,15 @@ const Login: React.FC = memo(() => { ...@@ -22,16 +22,15 @@ const Login: React.FC = memo(() => {
password: "" password: ""
}) })
useEffect(() => { // useEffect(() => {
dispatch(fetchUsers()); // dispatch(fetchUsers());
}, []); // }, []);
useEffect(() => { useEffect(() => {
if (user) { if (user) {
navigate('/products') navigate('/products')
} else { } else {
navigate('/login') navigate('/login')
} }
}, [user]) }, [user])
const handleSubmit = async (e: any) => { const handleSubmit = async (e: any) => {
...@@ -39,7 +38,6 @@ const Login: React.FC = memo(() => { ...@@ -39,7 +38,6 @@ const Login: React.FC = memo(() => {
await axios.post('http://localhost:4000/login', values) await axios.post('http://localhost:4000/login', values)
.then((res) => { .then((res) => {
dispatch(loginUser(res.data.user)) dispatch(loginUser(res.data.user))
// console.log(res.data.user)
navigate("/products") navigate("/products")
}) })
.catch((err) => setError(err.response.data.message)) .catch((err) => setError(err.response.data.message))
......
...@@ -117,14 +117,16 @@ const Register = () => { ...@@ -117,14 +117,16 @@ const Register = () => {
await axios.post('http://localhost:4000/registeruser', values) await axios.post('http://localhost:4000/registeruser', values)
.then((res) => { .then((res) => {
navigate("/login") navigate("/login")
// console.log(res.data)
}) })
.catch((err) => console.log(err)) .catch((err) =>{
setUserErr({...userErr,userIdErr:err.response.data.error})
console.log(err)
})
} }
useEffect(() => { // useEffect(() => {
dispatch(fetchUsers()); // dispatch(fetchUsers());
}, []); // }, []);
return ( return (
<div className='wrapper'> <div className='wrapper'>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment