'register-validations-updated'

parent fc961257
......@@ -81,14 +81,14 @@ app.post('/registeruser', checkUserIdExists, (req, res) => {
});
// Get Users endpoint
// app.get('/users', (req, res) => {
// // db.collection('users').find({}, { projection: { _id: false, userId: true, password: true } }).toArray()
// db.collection('users').find({}, { projection: { _id: false } }).toArray()
// .then(result => {
// res.send(result);
// })
// .catch(error => res.status(500).send(error));
// });
app.get('/users', (req, res) => {
// db.collection('users').find({}, { projection: { _id: false, userId: true, password: true } }).toArray()
db.collection('users').find({}, { projection: { _id: false } }).toArray()
.then(result => {
res.send(result);
})
.catch(error => res.status(500).send(error));
});
//login api
app.post('/login', async (req, res) => {
......
......@@ -22,16 +22,15 @@ const Login: React.FC = memo(() => {
password: ""
})
useEffect(() => {
dispatch(fetchUsers());
}, []);
// useEffect(() => {
// dispatch(fetchUsers());
// }, []);
useEffect(() => {
if (user) {
navigate('/products')
} else {
navigate('/login')
}
}, [user])
const handleSubmit = async (e: any) => {
......@@ -39,7 +38,6 @@ const Login: React.FC = memo(() => {
await axios.post('http://localhost:4000/login', values)
.then((res) => {
dispatch(loginUser(res.data.user))
// console.log(res.data.user)
navigate("/products")
})
.catch((err) => setError(err.response.data.message))
......
......@@ -117,14 +117,16 @@ const Register = () => {
await axios.post('http://localhost:4000/registeruser', values)
.then((res) => {
navigate("/login")
// console.log(res.data)
})
.catch((err) => console.log(err))
.catch((err) =>{
setUserErr({...userErr,userIdErr:err.response.data.error})
console.log(err)
})
}
useEffect(() => {
dispatch(fetchUsers());
}, []);
// useEffect(() => {
// dispatch(fetchUsers());
// }, []);
return (
<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