mufidu / booku

0 stars 1 forks source link

Sweep: Refactor password hashing code. #113

Closed mufidu closed 5 months ago

mufidu commented 5 months ago

Details

There is some codes to hash password in routes/auth.routes.js and routes/profile.routes.js. Refactor it so we only need to write it once and just call it when needed.

Checklist - [X] Create `utils/passwordUtil.js` ✓ https://github.com/mufidu/booku/commit/9f07d8464bf61cf054e905e836ac26d3340a0e6c [Edit](https://github.com/mufidu/booku/edit/sweep/refactor_password_hashing_code/utils/passwordUtil.js) - [X] Running GitHub Actions for `utils/passwordUtil.js` ✓ [Edit](https://github.com/mufidu/booku/edit/sweep/refactor_password_hashing_code/utils/passwordUtil.js) - [X] Modify `routes/auth.routes.js` ✓ https://github.com/mufidu/booku/commit/b6aa14ec41dbd84068648242edfe87fcb4855cb8 [Edit](https://github.com/mufidu/booku/edit/sweep/refactor_password_hashing_code/routes/auth.routes.js) - [X] Running GitHub Actions for `routes/auth.routes.js` ✓ [Edit](https://github.com/mufidu/booku/edit/sweep/refactor_password_hashing_code/routes/auth.routes.js) - [X] Modify `routes/profile.routes.js` ✓ https://github.com/mufidu/booku/commit/45e33417fcdf5b2e0eaa3091414571f633ed6bbc [Edit](https://github.com/mufidu/booku/edit/sweep/refactor_password_hashing_code/routes/profile.routes.js) - [X] Running GitHub Actions for `routes/profile.routes.js` ✓ [Edit](https://github.com/mufidu/booku/edit/sweep/refactor_password_hashing_code/routes/profile.routes.js)
sweep-ai[bot] commented 5 months ago

🚀 Here's the PR! #114

See Sweep's progress at the progress dashboard!
💎 Sweep Pro: I'm using GPT-4. You have unlimited GPT-4 tickets. (tracking ID: 6f1c3603da)

[!TIP] I can email you next time I complete a pull request if you set up your email here!


Actions (click)


Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/mufidu/booku/blob/49574b93a323406d9ae5d0db769d5cc3e5988588/routes/auth.routes.js#L7-L33 https://github.com/mufidu/booku/blob/49574b93a323406d9ae5d0db769d5cc3e5988588/routes/profile.routes.js#L18-L41 https://github.com/mufidu/booku/blob/49574b93a323406d9ae5d0db769d5cc3e5988588/middleware/auth.middleware.js#L1-L21

Step 2: ⌨️ Coding

Ran GitHub Actions for 9f07d8464bf61cf054e905e836ac26d3340a0e6c:

--- 
+++ 
@@ -1,5 +1,6 @@
 const express = require('express');
 const bcrypt = require('bcrypt');
+const { hashPassword } = require('../utils/passwordUtil.js');
 const jwt = require('jsonwebtoken');
 const User = require('../models/user.model.js');

@@ -7,7 +8,7 @@

 router.post('/register', async (req, res) => {
   try {
-    const hashedPassword = await bcrypt.hash(req.body.password, 10);
+    const hashedPassword = await hashPassword(req.body.password);
     const user = new User({
       username: req.body.username,
       email: req.body.email,

Ran GitHub Actions for b6aa14ec41dbd84068648242edfe87fcb4855cb8:

--- 
+++ 
@@ -1,6 +1,7 @@
 const express = require('express');
 const User = require('../models/user.model.js');
 const bcrypt = require('bcrypt');
+const { hashPassword } = require('../utils/passwordUtil.js');

 const router = express.Router();

@@ -27,7 +28,7 @@
   if (username) updateData.username = username;
   if (email) updateData.email = email;
   if (password) {
-    const hashedPassword = await bcrypt.hash(password, 10);
+    const hashedPassword = await hashPassword(password);
     updateData.password = hashedPassword;
   }

Ran GitHub Actions for 45e33417fcdf5b2e0eaa3091414571f633ed6bbc:


Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/refactor_password_hashing_code.


🎉 Latest improvements to Sweep:
  • New dashboard launched for real-time tracking of Sweep issues, covering all stages from search to coding.
  • Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.
  • Use the GitHub issues extension for creating Sweep issues directly from your editor.

💡 To recreate the pull request edit the issue title or description. Something wrong? Let us know.

This is an automated message generated by Sweep AI.