feat: move /me route logic into getMe controller function#247
Conversation
|
Someone is attempting to deploy a commit to the Bhuvansh's projects Team on Vercel. A member of the Team first needs to authorize it. |
BHUVANSH855
left a comment
There was a problem hiding this comment.
The /me controller extraction looks good, but this PR also removes the rate limiter middleware imports and usages from multiple auth routes (signup, verify-signup, login, forgot-password, reset-password, and refresh-token).
This issue is only about moving the /me route logic into authController.js. Removing the existing rate limiters changes application behavior and weakens endpoint protection.
Please restore the existing rate limiter middleware and keep the PR focused on the /me refactor only.
|
Thanks for the review! You're right. The rate limiter middleware was restored in another PR that got merged after I had already created this branch, so those changes are missing here. I can sync my branch with the latest main branch and resolve the conflicts to restore the existing rate limiters while keeping this PR focused only on the If there are any specific conflicts or concerns, please let me know and I'll fix them accordingly. |
Thanks for the clarification. There are no additional concerns from my side. Please sync/rebase with the latest Once those unrelated changes are removed and the rate limiters are restored, I'll re-review the PR. |
📋 Pull Request — Move
/meRoute Logic intoauthController.js(getMe Controller)🔗 Related Issue
Closes #236 — Move /me route logic from authRoutes.js into authController.js (getMe controller)
📝 Summary
The
/me(get current user) route had its entire business logic — DB query, active-user check, response formatting, and error handling — written directly as an inline anonymous async function insideauthRoutes.js. This violates separation of concerns. This PR extracts that logic into a dedicatedgetMecontroller function inauthController.js, keeping the route file clean and focused only on routing.🐛 Root Cause
/meroute had inline DB query + business logic inauthRoutes.jsgetMefunction inauthController.jsasync (req, res) => { ... }with full DB and response logicrouter.get("/me", authMiddleware, getMe)getMewas not exported from controllergetMetomodule.exportsinauthController.js✅ Changes Made
Modified Files
controllers/authController.jsgetMeasync function with DB query, active-user check, response formatting, and error handling; exported frommodule.exportsroutes/authRoutes.jsgetMefrom controller; replaced inline anonymous async function withrouter.get("/me", authMiddleware, getMe)🎨 Code Quality Improvements
getMeis independently testable as a controller functionsignup,login,forgotPassword, etc. in the same projectauthRoutes.js🧪 Testing Checklist
GET /api/auth/mereturns correctid,name,email,rolefor authenticated user404when user not found in DB403when user account is deactivated (is_active === 0)500on server/DB errorauthMiddlewarestill correctly guards the route (returns401without valid token)/login,/signup,/logout, etc.)💻 How to Test Locally
📌 Coding Standards Followed