-
Notifications
You must be signed in to change notification settings - Fork 7
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
#165412914 add reset password endpoint #29
Conversation
f1f2de6
to
eb577a5
Compare
src/middlewares/errorCatcher.js
Outdated
@@ -0,0 +1,14 @@ | |||
import status from '../config/status'; | |||
|
|||
const errorCatcher = controller => async (req, res, next) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@luc-tuyishime give the function a more appropriate name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes applied
}); | ||
} | ||
sgMail.setApiKey(process.env.SENDGRID_API_KEY); | ||
const isSent = process.env.NODE_ENV === 'test' ? null : await sgMail.send(helper.sendgridMailTemplate.resetPassword(email, 'noreply@authersheaven.com')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we agreed on a sendEmail
helper that anyone can use
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes applied
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requested changes
055c1e1
to
a44f74c
Compare
}); | ||
} | ||
|
||
await helper.sendMail(email); // send mail |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@luc-tuyishime this should be wrapped by an error handler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have an async handler middleware that catches errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how has it been connected to this sendMail
function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I call the middleware in the routes.
the path to the route: routes/auth/local.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
src/middlewares/errorHandler.js
Outdated
@@ -0,0 +1,14 @@ | |||
import status from '../config/status'; | |||
|
|||
const errorHandler = controller => async (req, res, next) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function name has not been renamed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes applied
src/queries/users/updateUser.js
Outdated
* @param {object} condition where to update | ||
* @returns {boolean} return true when successfuly updated otherwise false | ||
*/ | ||
export default async (what = {}, condition = {}) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is the variable name what
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's what we want to update like a password.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
give it a more appropriate name. what
is not properly descriptive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have renamed the what name to value.
c139442
to
a537c7a
Compare
src/helpers/sendgridMailTemplate.js
Outdated
subject: 'Password Reset', | ||
html: `<p>You are receiving this because you (or someone else) have requested the reset of the password,<br> | ||
Click on the reset link bellow to complete the process<br> | ||
<a href='http://localhost:3000/api/v1/auth/reset/${tokenGenerator({ email: to }, { expiresIn: '2h' })}' target='_blank'>Reset Password</a></p>` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@luc-tuyishime, I propose the redirect URL be defined in an .env file so that we don't have to change this file in case we want to use another URL, so it maybe something like APP_URL
and the you use it this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense. Let's do that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes applied
src/tests/routes/auth.test.js
Outdated
passwordTwo: 'newpassworda', | ||
}; | ||
|
||
const newUser = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest you use the helper that I defined to generate fake user accounts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there shouldn't be static declaration objects here, create files to generate this data or reuse what is already there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes applied
src/helpers/sendgridMailTemplate.js
Outdated
subject: 'Password Reset', | ||
html: `<p>You are receiving this because you (or someone else) have requested the reset of the password,<br> | ||
Click on the reset link bellow to complete the process<br> | ||
<a href='http://localhost:3000/api/v1/auth/reset/${tokenGenerator({ email: to }, { expiresIn: '2h' })}' target='_blank'>Reset Password</a></p>` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense. Let's do that
src/tests/routes/auth.test.js
Outdated
passwordTwo: 'newpassworda', | ||
}; | ||
|
||
const newUser = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there shouldn't be static declaration objects here, create files to generate this data or reuse what is already there.
41c185c
to
d8a6cd7
Compare
aa7e1b5
to
db0e3c4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rebase your PR with a new commit from develop
ok thanks |
96ad798
to
0f62d24
Compare
* @export | ||
* @param {object} req | ||
* @param {object} res | ||
* @param {void} next |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good practice to put descriptive JSDOC comments
@@ -0,0 +1,32 @@ | |||
import db from '../models'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to use the same file naming convention.
{ expiresIn: '2h' } | ||
)}' target='_blank'>Reset Password</a></p>` | ||
}) | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better you create a reusable mail template.
So that other team member can use this helper to send emails
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This template is already a reusable template, you can use it to send emails.
0f62d24
to
75ce816
Compare
#165412912 validate user input on signup
75ce816
to
e008dcd
Compare
What does this PR do?
Description of Task to be completed?
Have the following endpoints working
POST api/v1/auth/reset/
UPDATE api/v1/auth/:token
How should this be manually tested?
Any background context you want to provide?
What are the relevant pivotal tracker stories?
Screenshots (if appropriate)