So i have managed to create a working signup form with react.js node and axios. I am using postgresql as database.
The problem comes when i want to login with store user. There were som error messages, but i fixed them all, now nothing happens.
This is from the backend.
app.post("/login", (req, res)=> {
const email = req.body.email;
const password = req.body.password;
try {
pool.query("SELECT * FROM users WHERE email = ?",
[email],
(err, result) => {
if(err){
res.send({err: err});
}else{
if(result.length > 0){
res.send(result);
bcrypt.compare(password, result.password, (error, response) => {
console.log("Result is " + response + '
');
})
}else{
res.send({message: "Wrong email or password"});
}
}
}
);
} catch (error) {
console.log("Something went wrong..");
}})
The things i try to log in the console does not appear on submit.
Here is the front-end
<form action="/login" method="POST" onSubmit={onSubmitForm}>
<Container component="main" maxWidth="xs">
<CssBaseline />
<Box
sx={{
marginTop: 8,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
}}
>
<Avatar sx={{ m: 1, bgcolor: 'secondary.main' }}>
<LockOutlinedIcon />
</Avatar>
<Typography component="h1" variant="h5">
Login
</Typography>
<Box noValidate sx={{ mt: 1 }}>
<TextField
margin="normal"
required
fullWidth
id="email"
label="Email Address"
name="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
autoComplete="email"
autoFocus
variant="standard"
/>
<TextField
margin="normal"
required
fullWidth
name="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
label="Password"
type="password"
id="password"
autoComplete="current-password"
variant="standard"
/>
<Button
type="submit"
value="submit"
onClick={() => onSubmitForm}
fullWidth
variant="contained"
sx={{ mt: 3, mb: 2 }}
style={{backgroundColor: "#282c34"}}
>
Log ind
</Button>
<Grid container>
<Grid item xs>
<Link href="/forgotpsw" variant="body2">
Glemt password?
</Link>
</Grid>
<Grid item>
</Grid>
</Grid>
</Box>
</Box>
</Container>
</form>
Also the onSubmit that is being called is here
const onSubmitForm = async (e) => {
e.preventDefault();
try{
const response = await Axios.post("http://localhost:5000/login", {
email,
password
}).then(
//setSuccess(true)
)
}catch(err){
console.log(err);
}
}
Any help would be appreciated, I can't seem to find any soloution :(