Reset password through email

This commit is contained in:
Omar 2018-12-26 18:03:10 -08:00
parent 35f15fd215
commit b9a38a3d96
3 changed files with 29 additions and 2 deletions

View File

@ -13,6 +13,7 @@ function router(app) {
app.post('/auth/phone/verify', AuthHandlers.verifyPhoneCode);
app.post('/auth/signin', AuthHandlers.signin);
app.put('/auth/signup', AuthHandlers.signup);
app.post('/auth/passwordReset', AuthHandlers.sendPasswordResetEmail)
// Users Endpoints
app.get('/users/by/phone', UserHandlers.findNetworkByPhone);

View File

@ -61,6 +61,14 @@ function createNewUser(user) {
});
}
/**
* Sends a password reset email
* @param {email} email
*/
function resetPassword(email) {
return firebase.auth().sendPasswordResetEmail(email).catch( error => { throw { error: error.code }; });
}
/**
*
* @param {string} phone
@ -157,7 +165,8 @@ module.exports = {
signinWithTagferId,
signinWithEmail,
createNewUser,
createNewSessionId
createNewSessionId,
resetPassword
};
// function signinWithTagferId1(tagferId, password, callback) {

View File

@ -107,10 +107,27 @@ function signup(req, res) {
});
}
/**
* Endpoint: auth/passwordReset
* Send a reset password link to the email
* @param {Object} req { email: String }
* @param {Object} res {} | { error: String }
*/
function sendPasswordResetEmail(req, res) {
const { email } = req.body;
const verifier = () => email;
if (!utils.isAppSecretValid(req,res) || !utils.isBodyValid(verifier, res)) {
return;
}
dao.resetPassword(email).then(() => res.json({}) ).catch( error => res.json(error))
}
module.exports = {
doesAttributeExist,
sendPhoneCode,
verifyPhoneCode,
signin,
signup
signup,
sendPasswordResetEmail
};