switched from success message on json to http status
This commit is contained in:
@@ -28,7 +28,6 @@ document.getElementById('signupForm').addEventListener('submit',async function (
|
||||
}
|
||||
|
||||
|
||||
|
||||
const response = await fetch ('/auth/signup', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
||||
12
index.js
12
index.js
@@ -54,7 +54,7 @@ app.post('/auth/logout', (req, res) => {
|
||||
res.clearCookie('io', {
|
||||
path: '/'
|
||||
});
|
||||
res.status(200).json({ message: 'Successfully logged out', success: true});
|
||||
res.status(200).json({ message: 'Successfully logged out' });
|
||||
});
|
||||
|
||||
// get JWT token API
|
||||
@@ -89,17 +89,16 @@ app.post('/auth/changepassword', async (req, res) => {
|
||||
const match = await bcrypt.compare(cPassword, result.rows[0].password);
|
||||
// if not return information
|
||||
if(!match){
|
||||
return res.json({ message: 'Current password is invalid', success: false })
|
||||
return res.status(401).json({ message: 'Current password is invalid' })
|
||||
}
|
||||
// hash password
|
||||
const salt = await bcrypt.genSalt(saltRounds);
|
||||
const hash = await bcrypt.hash(nPassword, salt);
|
||||
await changePassword(username, hash);
|
||||
|
||||
//TODO make href to login screen on front after success!!!
|
||||
return res.status(200).json({ message: 'Successfully changed password', success: true });
|
||||
return res.status(200).json({ message: 'Successfully changed password' });
|
||||
} catch (err) {
|
||||
return res.status(500).json({ message: 'Failed to change password', success: false});
|
||||
return res.status(500).json({ message: 'Failed to change password' });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -246,9 +245,10 @@ async function loginUser(req, res) {
|
||||
});
|
||||
req.session.loggedin = true;
|
||||
req.session.username = username;
|
||||
res.status(200).json({ message: 'Successfully logged in', success: true });
|
||||
res.status(200).json({ message: 'Successfully logged in' });
|
||||
} else {
|
||||
res.send('Incorrect Username or Password!');
|
||||
return res.status(401).json({ message: 'Incorrect Username or Password!'})
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error executing query', error);
|
||||
|
||||
Reference in New Issue
Block a user