Feat email password reset (#730)

* change name of auth.service to AuthService

* Add emailEnabled to config api

* Setup email

* update nodemailer version

* add translations

* update .env.example

* clean up console.log's)

* refactor RequestPasswordReset component

* chore: rebuild package-lock.json

---------

Co-authored-by: Daniel Avila <messagedaniel@protonmail.com>
This commit is contained in:
Dan Orlando 2023-07-31 19:37:46 -07:00 committed by GitHub
parent 2faeebfae2
commit 30a49ae611
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 221 additions and 171 deletions

View file

@ -125,16 +125,26 @@ const requestPasswordReset = async (email) => {
const link = `${domains.client}/reset-password?token=${resetToken}&userId=${user._id}`;
sendEmail(
user.email,
'Password Reset Request',
{
name: user.name,
link: link,
},
'./template/requestResetPassword.handlebars',
);
return { link };
const emailEnabled =
!!process.env.EMAIL_SERVICE &&
!!process.env.EMAIL_USERNAME &&
!!process.env.EMAIL_PASSWORD &&
!!process.env.EMAIL_FROM;
if (emailEnabled) {
sendEmail(
user.email,
'Password Reset Request',
{
name: user.name,
link: link,
},
'requestPasswordReset.handlebars',
);
return { link: '' };
} else {
return { link };
}
};
/**
@ -170,7 +180,7 @@ const resetPassword = async (userId, token, password) => {
{
name: user.name,
},
'./template/resetPassword.handlebars',
'resetPassword.handlebars',
);
await passwordResetToken.deleteOne();