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', {
|
const response = await fetch ('/auth/signup', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
12
index.js
12
index.js
@@ -54,7 +54,7 @@ app.post('/auth/logout', (req, res) => {
|
|||||||
res.clearCookie('io', {
|
res.clearCookie('io', {
|
||||||
path: '/'
|
path: '/'
|
||||||
});
|
});
|
||||||
res.status(200).json({ message: 'Successfully logged out', success: true});
|
res.status(200).json({ message: 'Successfully logged out' });
|
||||||
});
|
});
|
||||||
|
|
||||||
// get JWT token API
|
// 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);
|
const match = await bcrypt.compare(cPassword, result.rows[0].password);
|
||||||
// if not return information
|
// if not return information
|
||||||
if(!match){
|
if(!match){
|
||||||
return res.json({ message: 'Current password is invalid', success: false })
|
return res.status(401).json({ message: 'Current password is invalid' })
|
||||||
}
|
}
|
||||||
// hash password
|
// hash password
|
||||||
const salt = await bcrypt.genSalt(saltRounds);
|
const salt = await bcrypt.genSalt(saltRounds);
|
||||||
const hash = await bcrypt.hash(nPassword, salt);
|
const hash = await bcrypt.hash(nPassword, salt);
|
||||||
await changePassword(username, hash);
|
await changePassword(username, hash);
|
||||||
|
|
||||||
//TODO make href to login screen on front after success!!!
|
return res.status(200).json({ message: 'Successfully changed password' });
|
||||||
return res.status(200).json({ message: 'Successfully changed password', success: true });
|
|
||||||
} catch (err) {
|
} 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.loggedin = true;
|
||||||
req.session.username = username;
|
req.session.username = username;
|
||||||
res.status(200).json({ message: 'Successfully logged in', success: true });
|
res.status(200).json({ message: 'Successfully logged in' });
|
||||||
} else {
|
} else {
|
||||||
res.send('Incorrect Username or Password!');
|
res.send('Incorrect Username or Password!');
|
||||||
|
return res.status(401).json({ message: 'Incorrect Username or Password!'})
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error executing query', error);
|
console.error('Error executing query', error);
|
||||||
|
|||||||
Reference in New Issue
Block a user