-
Notifications
You must be signed in to change notification settings - Fork 0
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
add register endpoint #53
Conversation
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.
basically fix stuff that's not passing the linter
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've stolen package-lock.json from my branch to fix this. I do not have enough expertise to know how. Does @shangzhel know how?
Also may @shangzhel confirm what I've observed from bcrypt documentation?
server/src/api/register.ts
Outdated
// generate a new user document in the user collection | ||
await this.Users.create({ | ||
username, | ||
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.
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.
@chomosuke will this work when zhangzhe's login use this V
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.
Yes, that's exactly why i'm asking you to hash it again
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.
If you don't hash it again, it won't work
server/src/__tests__/api/register.ts
Outdated
@@ -50,7 +50,6 @@ describe('register unit tests', () => { | |||
expect(res.sendStatus).toBeCalledTimes(1); | |||
// check whether a new user is created in the db | |||
expect(router.Users.create).toBeCalledTimes(1); | |||
expect(router.Users.create).toBeCalledWith({ username, 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.
You can still check whether the hash is correct by using compareSync with bcrypt, as I've shown you in the screenshot of my last review.
Or as shangzhe has done in his login endpoint.
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.
You NEED TO test your code with a local database and postman. There's one very obvious bug I had to fix that can only be found by manual integration testing.
Even if we write our own integration test. You should still manually test to see if stuff work.
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.
Minor changes needed, otherwise good.
server/src/api/register.ts
Outdated
// ensure there is no existing identical username | ||
if (users.length === 0) { | ||
// generate a new user document in the user collection | ||
const hashedPw = hashSync(password, genSaltSync()); |
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.
Use the async bcrypt functions hash
and genSalt
, and await them. No sense in blocking when it's not necessary nor inconvenient.
server/src/__tests__/api/register.ts
Outdated
expect(router.Users.create).toBeCalledTimes(1); | ||
|
||
const firstParameter = ( | ||
router.Users.create as jest.MockedFunction<typeof router.Users.create> |
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.
You can avoid this type cast by declaring create
as a local variable then assigning it to the mock Users object.
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.
Looks good to me.
Just gonna merge it because it's no longer WIP. |
close #28