Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API to modify user password #50

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

API to modify user password #50

wants to merge 8 commits into from

Conversation

bojonvi
Copy link
Collaborator

@bojonvi bojonvi commented Nov 2, 2021

This PR aims to implement an API for the front-end to use in order to modify the user's password.

Fixes #47

@bojonvi bojonvi requested a review from jcads November 2, 2021 05:51
if (merchant && (await merchant.isCorrectPassword(currentPass))) {
const salt = await bcrypt.genSalt(10);
const password = await bcrypt.hash(newPass, salt);
merchant = await Merchant.findByIdAndUpdate(req.user._id, { password });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is too expensive, I think we should be able to do it like this.

Suggested change
merchant = await Merchant.findByIdAndUpdate(req.user._id, { password });
merchant.password = password;

We want to minimize DB calls as much as possible.

Comment on lines 118 to 124
async function changePassword(req, res) {
const { currentPass, newPass } = req.body;
let merchant = await Merchant.findById(req.user._id);
if (merchant && (await merchant.isCorrectPassword(currentPass))) {
const salt = await bcrypt.genSalt(10);
const password = await bcrypt.hash(newPass, salt);
merchant = await Merchant.findByIdAndUpdate(req.user._id, { password });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or more precise

Suggested change
async function changePassword(req, res) {
const { currentPass, newPass } = req.body;
let merchant = await Merchant.findById(req.user._id);
if (merchant && (await merchant.isCorrectPassword(currentPass))) {
const salt = await bcrypt.genSalt(10);
const password = await bcrypt.hash(newPass, salt);
merchant = await Merchant.findByIdAndUpdate(req.user._id, { password });
async function changePassword(req, res) {
const { currentPass, newPass } = req.body;
const salt = await bcrypt.genSalt(10);
const password = await bcrypt.hash(newPass, salt);
merchant = await Merchant.findByIdAndUpdate(req.user._id, { password });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create an API for account change password
2 participants