Add password confirmation to `sign-up` action
Opened this issue · 1 comments
raq929 commented
Currently it doesn't check if the password and password confirmation match.
cob0910 commented
I used this template for my capstone and found a solution for this. I was about to open an issue when I found yours.
controllers/users.js
const signup = (req, res, next) => {
let credentials = req.body.credentials;
let user = { email: credentials.email, password: credentials.password};
getToken()
.then(token => user.token = token)
// needed to add ternary to ensure new and old passwords match before saving new user
.then(() =>
req.body.credentials.password !== req.body.credentials.password_confirmation ?
Promise.reject(new HttpError(404)) : new User(user).save())
.then(user =>
res.status(201).json({ user }))
.catch(makeErrorHandler(res, next));
};
scripts/sign-up.sh
API="http://localhost:4741"
URL_PATH="/sign-up"
curl "${API}${URL_PATH}" \
--include \
--request POST \
--header "Content-Type: application/json" \
--data '{
"credentials": {
"email": "'"${EMAIL}"'",
"password": "'"${PASS}"'",
"password_confirmation": "'"${PASS_CON}"'"
}
}'
echo