Skip to content

PR: Implement Request Page Components (Card, Requests, Reject Modal)#232

Open
codewkaushik404 wants to merge 29 commits intoOpenLake:mainfrom
codewkaushik404:feature/certificate
Open

PR: Implement Request Page Components (Card, Requests, Reject Modal)#232
codewkaushik404 wants to merge 29 commits intoOpenLake:mainfrom
codewkaushik404:feature/certificate

Conversation

@codewkaushik404
Copy link

@codewkaushik404 codewkaushik404 commented Feb 20, 2026

Changes Introduced

  • Added:
    • Request page layout and structure.
    • Reusable Card component for displaying request details.
    • Requests component to manage and render multiple request items.
    • Modal component for rejecting requests with proper UI interaction.
  • Updated:
    • Integrated request components into the main workflow.
    • Connected modal state handling with request actions.

Why This Change?

  • Problem: The application lacked a structured interface for viewing and managing incoming requests.
  • Solution: Implemented a dedicated Requests page with modular components and a rejection modal to improve request handling.
  • Impact:
    • Improves admin workflow by providing a clean UI to review and manage requests.
    • Enhances user experience with structured request cards.
    • Adds rejection functionality through an interactive modal.

Screenshots / Video (if applicable)

Before After
N/A
image image |

Testing

  • [] Ran unit tests and all passed (npm test in the relevant directory).
  • Manually tested the following scenarios:
    • [x]Test Case 1:** Open Requests page → Requests render correctly.
    • [x]Test Case 2:** Click Reject → Modal opens successfully.
    • [x]Test Case 3:** Confirm rejection → Modal closes and state updates correctly.
  • Tested on different browsers (Chrome, Firefox) for UI changes.
  • Verified there are no new console warnings or errors.

Documentation Updates

  • Updated the README.md with new instructions.
  • Added clear code comments where logic is complex.
  • N/A

Checklist

  • I have created a new branch for this PR (git checkout -b feature/request-page-components).
  • I have starred the repository.
  • My code follows the project's coding style and conventions.
  • My commit messages are clear and follow the project's guidelines.
  • I have performed a self-review of my own code.
  • I have added tests that prove my fix is effective or that my feature works.
  • All new and existing tests passed locally with my changes.
  • This PR introduces no breaking changes (or they are clearly documented).

Deployment Notes

  • Requires a database migration/schema update.
  • Requires new environment variables to be set.
  • N/A

💬Additional Notes

  • Components are designed to be reusable for future request-related features.
  • UI structure allows easy integration of approval or additional action workflows in future updates.

Summary by CodeRabbit

Release Notes

  • New Features
    • Multi-method authentication now supports Google OAuth and traditional username/password login.
    • New certificate management system enabling batch certificate creation and tracking.
    • Request management interface for coordinating room and event bookings.
    • Enhanced user onboarding with improved form validation and better institution-specific email enforcement.
    • Updated dashboard navigation with new Certificates and Requests sections.

Switched to session-based authentication and configured persistent session storage with connect-mongo.
…ession-based authentication and configured persistent session storage with connect-mongo.
@vercel
Copy link

vercel bot commented Feb 20, 2026

@codewkaushik404 is attempting to deploy a commit to the openlake's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 20, 2026

Walkthrough

This PR significantly restructures the backend's data models and authentication system, migrating from a monolithic schema file to individual model files with enhanced user authentication via Passport and bcrypt. It introduces certificate batch management, JWT-based middleware, and MongoDB session storage. The frontend is updated with new context hooks, pages for certificates and requests, and refactored authentication flows.

Changes

Cohort / File(s) Summary
Database Schema Refactoring
backend/models/schema.js, backend/models/userSchema.js, backend/models/feedbackSchema.js, backend/models/achievementSchema.js, backend/models/eventSchema.js, backend/models/positionSchema.js, backend/models/positionHolderSchema.js, backend/models/organizationSchema.js
Decomposed monolithic schema.js into individual model files with comprehensive field definitions, indexes, and timestamps. Removed 7 major models from schema.js exports; added pre-save hooks for password hashing in userSchema.
Certificate Management System
backend/models/certificateSchema.js, backend/controllers/certificateController.js, backend/routes/certificateRoutes.js, backend/utils/batchValidate.js
Introduced CertificateBatch and Certificate schemas with status tracking and approval workflows. Added createBatch controller with validation, approver lookup, and user verification. New batch validation utility with Zod schemas.
Authentication & Session Management
backend/config/passportConfig.js, backend/middlewares/isAuthenticated.js, backend/utils/authValidate.js, backend/index.js, backend/config/db.js
Implemented Google OAuth and Local Passport strategies with session serialization. Added jwtIsAuthenticated middleware for token-based auth. Integrated MongoStore for session persistence and cookie-parser. Updated DB connection to remove deprecated Mongoose options.
Backend Import Refactoring
backend/controllers/analyticsController.js, backend/controllers/dashboardController.js, backend/controllers/eventControllers.js, backend/routes/achievements.js, backend/routes/analytics.js, backend/routes/announcements.js, backend/routes/events.js, backend/routes/feedbackRoutes.js, backend/routes/onboarding.js, backend/routes/orgUnit.js, backend/routes/positionRoutes.js, backend/routes/profile.js, backend/routes/skillsRoutes.js
Updated all controller and route imports from combined schema requires to individual model imports. Standardized isAuthenticated imports from default to named exports.
Authentication Routes Overhaul
backend/routes/auth.js
Rewrote login, registration, and Google OAuth flows with custom Passport callbacks, explicit error handling, and structured JSON responses. Updated registration with Zod validation and user creation with strategy field.
Package Dependencies
backend/package.json
Replaced body-parser with express.json(); removed passport-local-mongoose and mongoose-findorcreate. Added bcrypt, connect-mongo, cookie-parser, zod, and uuid.
Frontend Context & Hooks
frontend/src/context/AdminContext.js, frontend/src/context/RequestContext.js, frontend/src/hooks/useSidebar.js, frontend/src/hooks/useAuth.js
Created useAdminContext hook replacing direct context usage. Added RequestContext with status counters. Refactored useAuth to delegate state updates through handleLogin. Removed showLogout state from useSidebar.
Frontend Authentication Pages
frontend/src/Components/Auth/Login.jsx, frontend/src/Components/Auth/Register.jsx, frontend/src/Components/Auth/UserOnboarding.jsx
Updated Login with response envelope handling and Google OAuth button redirect. Added controlled form submission in Register with loading state. Enhanced Onboarding with useAdminContext hook, admission year validation, and Navigate-based routing.
Frontend Request Management
frontend/src/Components/Requests/Requests.jsx, frontend/src/Components/Requests/Card.jsx, frontend/src/Components/Requests/viewModal.jsx, frontend/src/Components/Requests/editModal.jsx, frontend/src/Components/Requests/ui.jsx, frontend/src/pages/requestsPage.jsx
Introduced complete request management UI with RequestsTable, status filtering, search, and modal views for editing/viewing. Added UI component library (Overlay, Pill, color tokens). Supports approve/reject actions with role-based button visibility.
Frontend Certificate Management
frontend/src/Components/Certificates/CertificatesList.jsx, frontend/src/pages/certificatesPage.jsx
Added certificates dashboard with filtering by status, search functionality, and download/view actions. Includes loading and error states with mocked data placeholder.
Frontend Navigation & Layout
frontend/src/config/navbarConfig.js, frontend/src/config/dashboardComponents.js, frontend/src/Components/common/Sidebar.jsx, frontend/src/Components/Dashboard/Sidebar.jsx
Expanded navbar config with certificates, requests, templates, and role-specific entries. Added certificates and requests to dashboardComponents. Rewrote Sidebar with fixed widths, inline logout toggle, and limited visible items. Removed old Dashboard/Sidebar.jsx.
Frontend Service & Utility Updates
frontend/src/services/auth.js, frontend/src/Components/Auth/RoleRedirect.jsx, frontend/src/Components/Dashboard/Dashboard.jsx, frontend/src/Components/Dashboard/Home.jsx
Updated auth service signatures: registerUser and loginUser now accept username instead of email/ID. Modified fetchCredentials error handling. Updated component context usage to new useAdminContext hook. Added onboarding completion gate to Dashboard.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

  • PR #208: Adds actions_taken field to feedback schema in backend and surfaces it in FeedbackPreview UI component—directly related to feedback model changes in this PR.
  • PR #212: Modifies shared backend route files (achievements.js, skillsRoutes.js) with endpoint additions while this PR refactors the same files' imports and middleware patterns.

Suggested reviewers

  • harshitap1305

Poem

🐰 Schemas dance in files now free,
From monolith to harmony,
Passports guard with crypto strong,
Certificates and requests belong,
Context hooks make frontends bright,
This refactor feels just right! 🎓

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically describes the main additions: Requests page components (Card, Requests components, and Reject Modal), which aligns with the substantial changeset.
Description check ✅ Passed The PR description follows the template structure with all major sections completed: Changes Introduced, Why This Change, Testing, and Checklist. The description comprehensively explains what was added (Request page, Card component, Requests component, rejection modal) and why.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 11

Note

Due to the large number of review comments, Critical severity comments were prioritized as inline comments.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (15)
backend/config/db.js (1)

11-13: ⚠️ Potential issue | 🟠 Major

Server starts silently without a DB connection on failure.

The catch block only logs the error and returns normally. When connectDB is awaited in index.js at startup, a connection failure is silently absorbed and the HTTP server boots without a live database, causing all subsequent DB operations to fail at request time.

🛡️ Proposed fix
  } catch (error) {
    console.error("MongoDB Connection Error:", error);
+   process.exit(1);
  }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/config/db.js` around lines 11 - 13, The catch in connectDB currently
only logs the error which lets startup continue without a DB; update the
connectDB error handling (in backend/config/db.js, function connectDB) to fail
fast by either rethrowing the caught error or calling process.exit(1) after
logging so the awaited call in index.js rejects and the server does not start
without a DB; ensure you preserve the existing log (console.error) but then
propagate the failure (throw error or return Promise.reject(error)) so callers
see the failure.
backend/controllers/analyticsController.js (2)

379-383: ⚠️ Potential issue | 🟠 Major

Unsafe property access on populated fields will crash the endpoint for orphaned references.

If a referenced user_id or position_id document has been deleted, Mongoose .populate() silently sets those fields to null. Accessing .personal_info.name, .username, or .title on null throws a TypeError, taking down the entire getClubCoordinatorAnalytics response.

🛡️ Proposed fix
-currentPositionHolders: team.map(h => ({
-  name: h.user_id.personal_info.name,
-  username: h.user_id.username,
-  position: h.position_id.title
-})),
+currentPositionHolders: team
+  .filter(h => h.user_id && h.position_id)
+  .map(h => ({
+    name: h.user_id.personal_info?.name,
+    username: h.user_id.username,
+    position: h.position_id.title,
+  })),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/controllers/analyticsController.js` around lines 379 - 383, The
current mapping in getClubCoordinatorAnalytics that builds
currentPositionHolders from team.map(h => ({ name: h.user_id.personal_info.name,
username: h.user_id.username, position: h.position_id.title })) will throw when
populated user_id or position_id are null; update the mapping to defensively
handle orphaned references by checking for null before property access (e.g.,
use optional chaining or explicit null checks on h.user_id and h.position_id),
provide safe fallback values like 'Unknown' or skip entries, and keep the symbol
names team, currentPositionHolders, getClubCoordinatorAnalytics and the map
callback intact so the change is easy to locate.

233-233: ⚠️ Potential issue | 🟡 Minor

Typo: "Analyltics" → "Analytics" in the error log message.

✏️ Proposed fix
-console.error("President Dashboard Analyltics Error:", error);
+console.error("President Dashboard Analytics Error:", error);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/controllers/analyticsController.js` at line 233, Fix the typo in the
error log inside analyticsController.js: update the console.error call that
currently logs "President Dashboard Analyltics Error:" to correctly read
"President Dashboard Analytics Error:" so the message uses "Analytics" (locate
the console.error(...) in the President Dashboard error handling block).
backend/models/passportConfig.js (1)

55-66: ⚠️ Potential issue | 🟠 Major

serializeUser stores the full user object in the session — PII leak risk.

done(null, user) serializes the entire Mongoose document (email, name, profile picture, role, etc.) into the session store. Any session store breach (or accidental log) exposes full user PII. The standard and safe pattern is to serialize only the opaque ID; the deserializer already fetches the fresh record from the DB on every request so nothing is lost.

🔒 Proposed fix
 passport.serializeUser((user, done) => {
-  done(null, user);
+  done(null, user._id.toString());
 });

 passport.deserializeUser(async (userKey, done) => {
   try {
-    let user = await User.findById(userKey._id);
+    let user = await User.findById(userKey);
     done(null, user);
   } catch (err) {
     done(err);
   }
 });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/models/passportConfig.js` around lines 55 - 66, serializeUser
currently stores the whole user object (done(null, user)) which leaks PII;
change passport.serializeUser to only serialize the user's ID (e.g., done(null,
user._id || user.id)) and update passport.deserializeUser to accept that id
(userId) and call User.findById(userId) (keeping the existing try/catch and
done(null, user) behavior); also add a defensive null/validation check in
deserializeUser to call done(null, false) or done(new Error(...)) if the id is
missing or no user is found.
backend/routes/orgUnit.js (1)

153-153: ⚠️ Potential issue | 🔴 Critical

Transaction atomicity broken: save(session) should be save({ session }).

Mongoose's Document.prototype.save() expects save([options]) where options.session is the ClientSession. Passing the ClientSession directly as the first argument means the session is not properly registered with the save operation, so newUnit is saved outside the transaction. If existingUser is found afterward and abortTransaction() is called, newUnit remains committed — leaving an orphaned org-unit.

Compare with the correct form on line 178: await newUser.save({ session });.

🐛 Proposed fix
-await newUnit.save(session);
+await newUnit.save({ session });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/routes/orgUnit.js` at line 153, The newUnit save is passing the
ClientSession object directly (newUnit.save(session)), which causes the document
to be written outside the transaction; change the call to pass an options object
with the session (i.e., use newUnit.save({ session })) so the save participates
in the transaction; update the save invocation near the newUnit creation (same
area that checks existingUser and may call abortTransaction) to match how
newUser.save({ session }) is used.
backend/routes/events.js (3)

271-280: ⚠️ Potential issue | 🟠 Major

GET /:id silently returns null (HTTP 200) when the event is not found.

findById() returns null for a missing document; res.json(null) sends an HTTP 200 with a null body rather than a proper 404. Callers cannot distinguish "event exists but is empty" from "no such event".

🐛 Proposed fix
  const event = await Event.findById(req.params.id)
    .populate("organizing_unit_id", "name")
    .populate("organizers", "personal_info.name");
+ if (!event) return res.status(404).json({ message: "Event not found." });
  res.json(event);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/routes/events.js` around lines 271 - 280, The GET handler for
router.get("/:id") uses Event.findById(...) and blindly returns res.json(event),
which sends HTTP 200 with a null body when not found; update the async route
handler to check the result of Event.findById (the variable event) and if it's
null respond with res.status(404).json({ message: "Event not found" })
(otherwise continue to return the event), keeping the existing catch block for
server errors and error logging intact; locate this logic in the
router.get("/:id", async (req, res) => { ... }) function and modify the
post-findById flow accordingly.

444-477: ⚠️ Potential issue | 🟡 Minor

Remove debug console.log dumps from the production PUT route.

Lines 444–467 log the full request body and event document (before and after update) on every call. This is a performance overhead, can expose sensitive event data in server logs, and should not be in a merge-ready branch.

🐛 Proposed fix
-   // 🔍 DEBUG LOGS - START
-   console.log("\n=== 📝 UPDATE EVENT DEBUG ===");
-   console.log("Event ID:", eventId);
-   console.log("Updates received (full body):", JSON.stringify(updates, null, 2));
-   console.log("Number of fields to update:", Object.keys(updates).length);
-   console.log("Fields being updated:", Object.keys(updates));
-   console.log("========================\n");
-   const eventBefore = await Event.findById(eventId);
-   console.log("Event BEFORE update:", JSON.stringify(eventBefore, null, 2));
    const event = await Event.findByIdAndUpdate(eventId, updates, {
      new: true,
      runValidators: true,
    });
-   console.log("\n=== ✅ UPDATE RESULT ===");
-   console.log("Event AFTER update:", JSON.stringify(event, null, 2));
-   console.log("Update successful:", !!event);
-   console.log("========================\n");
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/routes/events.js` around lines 444 - 477, Remove the development
debug console.log dumps from the update PUT handler so production logs don't
contain full request bodies or database documents: delete the console.log block
that prints "=== 📝 UPDATE EVENT DEBUG ===" and the subsequent logs that print
eventId, updates, Event.findById result (eventBefore), and the "=== ✅ UPDATE
RESULT ===" logs; keep the actual update logic using Event.findByIdAndUpdate and
the existing try/catch and error handling (the function surrounding
Event.findById, Event.findByIdAndUpdate, and the catch block should remain
unchanged), but replace verbose debug prints with concise logging if needed
(e.g., a single info or error log) or remove them entirely.

415-420: ⚠️ Potential issue | 🟡 Minor

Add reviewed_at field to track review timestamp separately from request submission time.

requested_at is intended to capture when the room request was originally submitted (defined with default: Date.now in the schema), but it's being overwritten to the current timestamp when the request status is reviewed at line 418. This destroys the original submission timestamp.

Add a separate reviewed_at field to the room_requests schema to record when the request was actually reviewed, alongside the existing reviewed_by field.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/routes/events.js` around lines 415 - 420, The current handler that
updates a room request (using event.room_requests.id(requestId) and setting
request.status, request.requested_at, and request.reviewed_by) incorrectly
overwrites the original submission timestamp; instead, stop updating
request.requested_at and add a separate reviewed_at field on the room_requests
schema and set request.reviewed_at = new Date() when reviewing; update the code
that assigns reviewed_by to also assign reviewed_at, and ensure the
room_requests schema includes reviewed_at (Date) so the original requested_at
(default: Date.now) remains unchanged.
backend/routes/positionRoutes.js (1)

93-93: ⚠️ Potential issue | 🟡 Minor

Debug console.log(req.body) left in production path.

req.body in this route carries user_id, position_id, and appointment_details. Remove before merging.

🐛 Proposed fix
-  console.log(req.body);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/routes/positionRoutes.js` at line 93, Remove the stray
console.log(req.body) left in the route handler in positionRoutes.js — this
prints sensitive request payload (user_id, position_id, appointment_details) to
stdout; either delete the log line or replace it with a safe debug call (e.g.,
processLogger.debug) that omits or redacts sensitive fields before logging, and
ensure you only log non-sensitive identifiers if absolutely necessary in the
route handler where console.log(req.body) appears.
backend/controllers/dashboardController.js (1)

111-117: ⚠️ Potential issue | 🟠 Major

console.log(email) leaks PII to server logs.

User email is a personally-identifiable identifier. Logging it unconditionally in the CLUB_COORDINATOR branch violates GDPR/privacy best practices and can accumulate PII in log aggregation systems.

🛡️ Proposed fix
-  console.log(email);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/controllers/dashboardController.js` around lines 111 - 117, The
branch handling ROLES.CLUB_COORDINATOR currently logs the raw user email
(console.log(email)), leaking PII; remove that unconditional logging and instead
log only non-identifying context when OrganizationalUnit.findOne returns null
(e.g., a message including the role and request id or user id, or a
deterministic non-reversible hash of the email). Update the CLUB_COORDINATOR
case around the clubUnit lookup (the code using OrganizationalUnit.findOne and
the console.log(email) line) to delete the console.log(email) call and replace
it with a privacy-safe log (no raw email) or no log at all, or compute and log a
secure hash of the email if you need a traceable token.
backend/routes/feedbackRoutes.js (1)

50-50: ⚠️ Potential issue | 🔴 Critical

Typo: "ture" should be "true"is_anonymous string check is broken.

The comparison is_anonymous === "ture" will never match, so a string "true" value from the client will be treated as false.

🐛 Proposed fix
-      is_anonymous: is_anonymous === "ture" || is_anonymous === true,
+      is_anonymous: is_anonymous === "true" || is_anonymous === true,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/routes/feedbackRoutes.js` at line 50, The is_anonymous string
comparison in feedbackRoutes.js is misspelled ("ture") so string "true" from
clients is treated as false; update the check in the feedback submission handler
that sets is_anonymous (variable is_anonymous) to compare against "true" (and
consider normalizing input with .toLowerCase() or accepting both boolean and
string forms) so that is_anonymous: is_anonymous === "true" || is_anonymous ===
true correctly detects true values.
backend/routes/onboarding.js (1)

8-23: ⚠️ Potential issue | 🔴 Critical

No input validation — Program.trim() will throw a TypeError if Program is missing.

None of the destructured body fields (add_year, Program, discipline, mobile_no) are validated before use. If Program is undefined, line 20 crashes with Cannot read properties of undefined (reading 'trim'). Similarly, add_year and discipline are passed directly to the DB without checks.

Add validation (or use a Zod schema like other routes in this PR) before accessing these fields.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/routes/onboarding.js` around lines 8 - 23, The handler is using
Program.trim(), add_year, and discipline directly which can throw when Program
is undefined and allows invalid data into the DB; add a validation step (e.g.,
Zod schema or explicit guards) that requires Program (string), discipline
(string), and add_year (number or numeric-string) before proceeding, return 400
on validation failure, and then use the validated values in the
User.findByIdAndUpdate call (or use safe access like (Program||'').trim() only
as a fallback). Update the onboarding handler to validate/parse add_year (e.g.,
parseInt) and discipline, and ensure mobile_no defaults to "" when missing
before constructing personal_info.
backend/routes/profile.js (1)

106-111: ⚠️ Potential issue | 🟠 Major

PII logged to console — updatedDetails can contain personal data.

Lines 110–111 log userId and updatedDetails (which may include name, email, phone, date of birth, hostel, room number, social links). This is a compliance/privacy risk in production. Remove or redact these logs.

🛡️ Suggested fix
-    console.log("Received userId:", userId);
-    console.log("Received updatedDetails:", updatedDetails);
+    // Avoid logging PII — use structured logging with redaction in production
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/routes/profile.js` around lines 106 - 111, The code is logging
sensitive PII (userId and updatedDetails) in the route handler for
router.put("/updateStudentProfile", isAuthenticated, async (req, res) => { ...
}); remove those console.log calls (or replace them with non-PII telemetry) so
that userId and updatedDetails are not printed; if you need logging for
debugging, log a redact-safe summary (e.g., operation start and sanitized user
identifier or request id) rather than the full updatedDetails object and ensure
any retained logs do not include name, email, phone, DOB, hostel, room, or
social links.
backend/routes/auth.js (2)

220-234: ⚠️ Potential issue | 🟡 Minor

console.log(req.params) leaks token to logs.

Line 223 logs req.params, which includes the JWT reset token. An attacker with log access could use this to reset arbitrary passwords. Remove or redact.

🛡️ Fix
-    console.log(req.params);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/routes/auth.js` around lines 220 - 234, The handler for
router.get("/reset-password/:id/:token") is leaking sensitive data by logging
req.params (which contains the reset token); remove the console.log(req.params)
call or replace it with a safe log that only includes non-sensitive fields
(e.g., log req.params.id or a redacted placeholder), ensuring you do not log the
token value anywhere in the resetPassword verification flow (refer to the route
handler function and the req.params variable).

237-260: ⚠️ Potential issue | 🔴 Critical

Critical regression: user.setPassword() no longer exists after the schema rewrite.

The userSchema.js was refactored to use a custom pre("save") hook for password hashing instead of the passport-local-mongoose plugin. The reset-password route at line 247 still calls user.setPassword(password, ...), which will throw TypeError: user.setPassword is not a function at runtime and break password resets entirely.

Set the password directly and let the pre-save hook handle hashing:

Proposed fix
   try {
     jwt.verify(token, secret);
-    user.setPassword(password, async (error) => {
-      if (error) {
-        return res.status(500).json({ message: "Error resetting password" });
-      }
-      await user.save();
-      return res
-        .status(200)
-        .json({ message: "Password has been reset successfully" });
-    });
+    user.password = password;
+    await user.save(); // pre-save hook hashes the password
+    return res
+      .status(200)
+      .json({ message: "Password has been reset successfully" });
   } catch (error) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/routes/auth.js` around lines 237 - 260, The reset-password handler
still calls the removed method user.setPassword(password, ...); update the
router.post("/reset-password/:id/:token") flow to assign the plain password
directly to the User document (e.g. user.password = password), then await
user.save() so the schema's pre("save") hook performs hashing, and handle errors
from save with proper status responses; remove the setPassword callback usage
and keep the existing jwt.verify try/catch around the save operation.
🟠 Major comments (13)
backend/utils/batchValidate.js-3-3 (1)

3-3: ⚠️ Potential issue | 🟠 Major

ObjectId regex accepts non-hex characters — will allow invalid MongoDB ObjectIds.

MongoDB ObjectIds are 24-character hex strings (0-9, a-f). The current regex /^[0-9a-zA-Z]{24}$/ also accepts non-hex characters like g-z and G-Z, meaning invalid IDs will pass validation but fail at the database layer.

🐛 Proposed fix
-const zodObjectId = zod.string().regex(/^[0-9a-zA-Z]{24}$/, "Invalid ObjectId");
+const zodObjectId = zod.string().regex(/^[0-9a-fA-F]{24}$/, "Invalid ObjectId");
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/utils/batchValidate.js` at line 3, The zodObjectId validator in
backend/utils/batchValidate.js currently allows non-hex characters; update the
regex used by zodObjectId so it only permits 24 hex characters (0-9 and a-f/A-F)
and keep the same "Invalid ObjectId" message; locate the zodObjectId constant
and replace its pattern with one that enforces exactly 24 hex digits.
frontend/src/services/auth.js-9-31 (1)

9-31: ⚠️ Potential issue | 🟠 Major

Inconsistent return shapes across service functions — callers can't safely consume these.

The functions in this module return wildly different shapes on success and error:

Function Success Error
fetchCredentials response.data throws
completeOnboarding response.data error.response (Axios response obj)
registerUser response (full Axios response!) error.response
loginUser res.data null

Specifically:

  • Line 27: registerUser returns the full Axios response object (with status, headers, config, etc.), while loginUser at line 38 returns res.data. This inconsistency means callers need to access response.data.data for registerUser vs result.someField for loginUser.
  • Lines 13-15 and 29-30: On error, completeOnboarding and registerUser return error.response (the raw Axios error response), which is a fundamentally different shape from the success path. Callers will need to check for status, data, etc.

Standardize all functions to return the same shape (e.g., always return response.data on success and null or a structured error object on error).

Proposed fix for registerUser
-    return response; 
+    return response.data; 
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/services/auth.js` around lines 9 - 31, completeOnboarding and
registerUser return inconsistent shapes (full axios response or error.response)
which breaks callers; update both to always return response.data on success and
a consistent error sentinel (e.g., null) on failure. Specifically, in
completeOnboarding replace returning error.response with null, and in
registerUser return response.data (not the whole response) on success and return
null in the catch block; ensure both functions keep the try/catch but normalize
their return shapes to response.data / null so callers can consume results
uniformly.
frontend/src/Components/Dashboard/Dashboard.jsx-15-15 (1)

15-15: ⚠️ Potential issue | 🟠 Major

Replace <div>Kaushik</div> with a proper fallback.

This substitutes what was previously the Home component with a raw developer string. Any user navigating to an unrecognised route will see "Kaushik" instead of a real UI. Restore the original fallback or use a proper "Not Found" / redirect component.

🐛 Proposed fix
-    DashboardComponents[selectedRoute] || (() => <div>Kaushik</div>);
+    DashboardComponents[selectedRoute] || Home;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/Components/Dashboard/Dashboard.jsx` at line 15, The fallback for
unknown routes was replaced with a developer string; revert to a proper UI by
replacing the inline <div>Kaushik</div> in DashboardComponents[selectedRoute] ||
(() => <div>Kaushik</div>) with the original Home component or a
NotFound/Redirect component. Locate the DashboardComponents array/object and the
selectedRoute usage in Dashboard.jsx and return the Home component (or a
dedicated NotFound component) as the default render function so users see the
expected UI for unrecognized routes.
frontend/src/Components/Certificates/CertificatesList.jsx-22-52 (1)

22-52: ⚠️ Potential issue | 🟠 Major

Mock data will ship to production; api import is dead code until the endpoint is wired.

The real API call is commented out and the TODO is untracked. Merge this only after the /api/certificates/:id endpoint is ready and the mock block is removed, or gate the mock behind a dev-only flag so it can't accidentally reach production.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/Components/Certificates/CertificatesList.jsx` around lines 22 -
52, The component CertificatesList.jsx currently assigns hard-coded
mockCertificates and calls setCertificates, and the api import remains unused;
either remove the mock block and dead import before merging or gate the mock
data behind an environment/dev-only flag so it never runs in production. Replace
the mockCertificates + setCertificates path with the real API call to fetch
/api/certificates/:id when that endpoint exists (or wrap the mock assignment in
a check like process.env.NODE_ENV === 'development' / a feature flag) and clean
up the unused api import to prevent shipping dead code.
backend/controllers/eventControllers.js-6-9 (1)

6-9: ⚠️ Potential issue | 🟠 Major

Sort field updated_at (snake_case) doesn't match the selected/used field updatedAt (camelCase).

Mongoose's built-in timestamps use camelCase (updatedAt). Sorting by updated_at references a non-existent field, so the .limit(4) result order is effectively undefined — the "latest events" may not be the latest ones at all.

🐛 Proposed fix
-  .sort({updated_at: -1})
+  .sort({updatedAt: -1})
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/controllers/eventControllers.js` around lines 6 - 9, The query that
builds latestEvents uses sort({updated_at: -1}) which references a non-existent
snake_case timestamp; change the sort to use Mongoose's camelCase timestamp
field (sort({updatedAt: -1})) so Event.find(...).sort(...) correctly orders by
the actual updatedAt field that is already being selected.
frontend/src/Components/Certificates/CertificatesList.jsx-14-64 (1)

14-64: ⚠️ Potential issue | 🟠 Major

Perpetual loading state when isUserLoggedIn is empty/null.

loading is initialised to true but the else branch (guard fails) never calls setLoading(false). Any user who lands on this page before isUserLoggedIn is populated — or without an active session — sees the "Loading certificates…" spinner indefinitely.

🐛 Proposed fix
    if (isUserLoggedIn && Object.keys(isUserLoggedIn).length > 0) {
      fetchCertificates();
+   } else {
+     setLoading(false);
    }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/Components/Certificates/CertificatesList.jsx` around lines 14 -
64, The useEffect/fetchCertificates flow leaves loading true when the guard if
(isUserLoggedIn && Object.keys(isUserLoggedIn).length > 0) fails; ensure
setLoading(false) is called in that case so the spinner doesn't show forever —
either initialize loading to false and only set true when starting
fetchCertificates, or add an else branch after the guard that calls
setLoading(false) (or explicitly setLoading(false) before returning) so that
setLoading is balanced whenever fetch is not invoked.
frontend/src/Components/Requests/Card.jsx-68-73 (1)

68-73: ⚠️ Potential issue | 🟠 Major

Object.assign(req, updatedRequest) mutates the parent's prop object in place.

Directly mutating props is a React anti-pattern — it bypasses React's rendering cycle, so the parent component won't know the data changed and won't re-render. This can lead to stale UI and subtle bugs.

Instead, lift the update to the parent via a callback, or maintain a local copy of the request in state.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/Components/Requests/Card.jsx` around lines 68 - 73, handleSave
currently mutates the prop object via Object.assign(req, updatedRequest), which
mutates the parent's prop and breaks React's render model; update handleSave to
avoid in-place mutation by calling a parent-provided updater (e.g.,
onUpdateRequest or similar prop) with the updatedRequest, or update a local copy
stored in state (e.g., useState for request) and setRequest(updatedCopy) instead
of mutating req directly; locate the handleSave function and replace the direct
Object.assign(req, updatedRequest) use with a call to the parent callback or a
setState update to ensure React re-renders.
backend/config/passportConfig.js-25-25 (1)

25-25: ⚠️ Potential issue | 🟠 Major

User email (PII) logged to stdout.

Logging raw email addresses may create compliance concerns (GDPR/institutional policy). Consider logging a redacted form or omitting the address entirely.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/config/passportConfig.js` at line 25, The console.log in the Google
OAuth flow is printing a user's raw email (profile.emails[0].value); remove or
replace this PII output in passportConfig.js by either omitting the address
entirely or logging a redacted/hash form (e.g., mask local-part or log only
domain) and use the app's logger (e.g., processLogger.warn/info) instead of
console.log to maintain consistent logging; update the OAuth verify callback
where console.log("Google OAuth blocked for: ", profile.emails[0].value) appears
to use the redacted value or no email.
frontend/src/Components/Requests/Requests.jsx-155-158 (1)

155-158: ⚠️ Potential issue | 🟠 Major

Missing key prop on <Card> inside .map().

React requires a unique key for list-rendered elements to avoid reconciliation bugs and console warnings. Each req already has an id field.

🐛 Proposed fix
-            <Card req={req} statusColor={statusColor} />
+            <Card key={req.id} req={req} statusColor={statusColor} />
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/Components/Requests/Requests.jsx` around lines 155 - 158, The
Card elements rendered in Requests.jsx inside the filteredRequests.map do not
include a unique key, causing React list-key warnings; update the mapping to
pass a key prop to the Card (e.g., key={req.id}) when rendering each <Card
req={req} statusColor={statusColor} /> so React can properly reconcile the list
(use req.id as the primary key and fall back to index only if id may be
missing).
backend/routes/onboarding.js-33-34 (1)

33-34: ⚠️ Potential issue | 🟠 Major

Internal error details leaked to client.

error.message can contain Mongoose validation errors, stack traces, or internal details. Return a generic message to the client and keep the detailed log server-side.

Proposed fix
     console.error("Onboarding failed:", error.message);
-    res.status(500).json({ message: error.message || "Onboarding failed"  });
+    res.status(500).json({ message: "Onboarding failed" });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/routes/onboarding.js` around lines 33 - 34, The route currently leaks
internal error details by returning error.message to the client; update the
onboarding error handling so that console.error (or your server logger) logs the
full error/stack (e.g., use console.error("Onboarding failed:", error) or
processLogger.error(error)) and change the response to a generic message like
res.status(500).json({ message: "Onboarding failed" }) instead of
res.status(500).json({ message: error.message || "Onboarding failed" }); locate
and update the console.error and res.status(...).json(...) calls inside the
onboarding route handler.
backend/routes/profile.js-17-31 (1)

17-31: ⚠️ Potential issue | 🟠 Major

Missing authorization check — any authenticated user can modify any profile.

All three routes (/photo-update, /photo-delete, /updateStudentProfile) accept an ID_No or userId from the request body/query and operate on that user's profile. There is no check that req.user owns the targeted profile. An authenticated user could update or delete another user's photo or profile data.

Compare the incoming ID_No/userId against req.user.user_id (or equivalent) before proceeding.

Also applies to: 80-90, 106-117

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/routes/profile.js` around lines 17 - 31, Add an ownership
authorization check to the profile routes so authenticated users cannot mutate
others' profiles: in the handlers for "/photo-update", "/photo-delete", and
"/updateStudentProfile" (the async route callbacks using ID_No or userId from
req.body/query), compare the supplied ID_No/userId with req.user.user_id (or the
canonical identifier on req.user) and immediately return a 403 Forbidden JSON
response if they differ; do this before calling User.findOne or performing any
update/delete and reuse the existing isAuthenticated middleware presence to
trust req.user.
backend/index.js-83-89 (1)

83-89: ⚠️ Potential issue | 🟠 Major

Server starts even if the DB connection fails.

connectDB() (per backend/config/db.js) catches and logs the error but does not re-throw or call process.exit(1). The await connectDB() here will resolve successfully even on failure, and the server will start listening without a working database. This leads to 500s on every request rather than a clear startup failure.

🛡️ Suggested fix — propagate DB errors

In backend/config/db.js, re-throw after logging:

   } catch (error) {
     console.error("MongoDB Connection Error:", error);
+    throw error;
   }

Or guard in index.js:

 (async function(){
-  await connectDB();
-  app.listen(process.env.PORT || 5000, () => {
-    console.log(`connected to port ${process.env.PORT || 5000}`);
-  });
+  try {
+    await connectDB();
+    app.listen(process.env.PORT || 5000, () => {
+      console.log(`connected to port ${process.env.PORT || 5000}`);
+    });
+  } catch (err) {
+    console.error("Failed to start server:", err);
+    process.exit(1);
+  }
 })();
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/index.js` around lines 83 - 89, connectDB() currently swallows DB
errors so await connectDB() in the IIFE can resolve even on failure; either (A)
modify the implementation in backend/config/db.js so connectDB() re-throws the
error after logging (preserve current log but throw the caught error) or (B)
update the startup IIFE in backend/index.js to check the result and abort
startup on failure (wrap await connectDB() in try/catch and call process.exit(1)
on error before calling app.listen). Target the connectDB() function in
backend/config/db.js and the IIFE that calls await connectDB() / app.listen in
backend/index.js.
backend/models/userSchema.js-24-30 (1)

24-30: ⚠️ Potential issue | 🟠 Major

Password hash can leak in API responses — add select: false.

The password field lacks select: false, so it is included in every query result by default. In backend/routes/profile.js line 228, the full user object (including the hashed password) is returned in the updatedStudent response. Even hashed passwords should never leave the server.

Adding select: false ensures password is excluded unless explicitly requested (e.g., in login flows via .select("+password")).

Proposed fix
     password: {
       type: String,
       required: function () {
         return this.strategy === "local";
       },
       minLength: 8,
+      select: false,
     },
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/models/userSchema.js` around lines 24 - 30, The password field on the
Mongoose schema (userSchema) is currently returned by default; add select: false
to the password schema definition so hashed passwords are excluded from query
results unless explicitly requested (e.g., with .select("+password") in login
flows). Update the password property in the userSchema (the password field
block) and ensure any code that needs the password (such as
authentication/login) uses .select("+password"); also check the profile route
where updatedStudent is returned to avoid sending the full user object with the
password.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 10

🧹 Nitpick comments (3)
frontend/src/hooks/useAuth.js (1)

21-29: Harden response-shape checks before calling handleLogin.

Current logic only checks falsy response; a truthy response without message leaves auth state ambiguous.

Suggested fix
 const response = await fetchCredentials();
-if(!response){
+if (!response?.success || !response?.message) {
   setIsUserLoggedIn(false);
+  setUserRole(null);
+  setIsOnboardingComplete(false);
   return;
 }
 
 const user = response.message;
 handleLogin(user);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/hooks/useAuth.js` around lines 21 - 29, The code assumes
fetchCredentials() returns an object with a message property but only checks for
a falsy response; update the logic in the caller (around fetchCredentials,
response, handleLogin) to verify the response shape before calling handleLogin —
e.g., ensure response && typeof response.message === "object" (or expected
primitive/fields) and that required user fields exist; if the check fails, call
setIsUserLoggedIn(false) and return, otherwise extract the user and call
handleLogin(user). Make this change where response is used and reference the
symbols fetchCredentials, response.message, handleLogin, and setIsUserLoggedIn.
frontend/src/Components/common/Sidebar.jsx (1)

11-11: Avoid hardcoded nav truncation (slice(0, 14)).

Line 11 silently hides items beyond index 13. This is fragile for future menu additions (e.g., requests/certificates growth).

Proposed fix
-  const visibleNavItems = navItems.slice(0, 14);
+  const visibleNavItems = navItems;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/Components/common/Sidebar.jsx` at line 11, The hardcoded
truncation visibleNavItems = navItems.slice(0, 14) in Sidebar.jsx silently hides
items; replace it with a configurable/dynamic approach: either read a
MAX_VISIBLE_NAV_ITEMS constant from config/env or a prop (e.g., maxVisible) and
use navItems.slice(0, maxVisible) or simply render all navItems and add a "Show
more" / collapsible behavior when length exceeds the threshold; update any
references to visibleNavItems accordingly (the navItems array and
visibleNavItems variable) and ensure unit/UI tests or prop types cover the new
maxVisible/config option.
frontend/src/services/auth.js (1)

24-35: Standardize service return/error contracts.

At Line 32 this returns full response, while other functions return .data or null. Mixing AxiosResponse | data | null | error.response makes callers brittle and caused control-flow issues nearby.

Suggested normalization pattern
 export async function registerUser(username, password, name) {
   try {
     const response = await api.post(`/auth/register`, {
       name,
       username,
       password,
     });
-    return response; 
+    return response.data;
   } catch (error) {
-    //console.error("Error obj is:",error.response);
-    return error.response;
+    throw error;
   }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/services/auth.js` around lines 24 - 35, The registerUser
function currently returns the full Axios response on success and returns
error.response on failure, which mixes response shapes; update registerUser to
return a normalized shape consistent with other auth services (e.g., return
response.data on success and null or a standardized error object on failure).
Locate registerUser in frontend/src/services/auth.js and change its success path
to return response.data and its catch path to return a consistent value (null or
an object like { error: error.response?.data || error.message }) so callers
receive a predictable contract.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@frontend/src/Components/common/Sidebar.jsx`:
- Line 2: The import path for the Logout component in Sidebar.jsx is wrong;
update the import statement that currently references "../Auth/Logout" to point
to the actual component location "../Logout" so the module resolves correctly;
locate the import line in Sidebar.jsx (the Logout import) and change the path,
then run a quick build or lint to verify the module is resolved.
- Line 82: The className on the Sidebar item contains conflicting text color
utilities (`text-zinc-400` and `text-white`); remove `text-zinc-400` and leave
`text-white` (in the template string used in the Sidebar component) so a single
text color governs the element, and check other Sidebar item className usages to
ensure only one text color utility is applied consistently.
- Around line 80-90: The Logout side-effect is currently triggered by mounting
<Logout /> inside the button subtree which ties the effect to rendering and
leaves loggingOut true on failures; instead, remove the <Logout /> mount and
implement an explicit async handler (e.g., handleLogout) called from the button
onClick that sets setLoggingOut(true), invokes the logout operation (either by
calling an exported logout function from the Logout component or by passing a
callback into the component), and then on success navigates/clears state and on
failure resets setLoggingOut(false) and surfaces an error so retry is possible;
update the Logout component to export a promise-returning logout function or
accept onComplete/onError callbacks so Sidebar can control the flow rather than
relying on mount effects.

In `@frontend/src/config/navbarConfig.js`:
- Line 83: Update the navbarConfig entry where the menu item object has key
"achievements" to change its label from "Achieve" to "Achievements" so the label
matches the key and reads clearly in navigation; locate the object with key
"achievements" (the entry containing label and icon, e.g., Trophy) and replace
the label string accordingly.
- Line 34: The navbar contains nav items with keys 'templates', 'batches',
'drafts', and 'submitted' that have no corresponding entries in the
dashboardComponents mapping, causing dead navigation; update the
dashboardComponents mapping to export components mapped to these keys (or
remove/disable the nav items) so each nav key in navbarConfig resolves to a real
component — locate the nav keys ('templates', 'batches', 'drafts', 'submitted')
in navbarConfig and add matching exports/entries in dashboardComponents (or
delete those keys from navbarConfig) to restore valid routing.
- Around line 69-71: The navbarConfig entries use plural keys that don't match
the dashboard registry and break coordinator routes; update the three objects in
the exported nav config (the entries with key "endorsements", "feedbacks", and
"pors") to use the registered keys "endorsement", "feedback", and "por"
respectively so they align with the dashboard registry and routing.

In `@frontend/src/hooks/useAuth.js`:
- Around line 27-29: Remove the debug log that prints the full user object to
the console to avoid exposing personal data: delete the console.log("User is:",
user) call in useAuth.js (the block that sets const user = response.message and
calls handleLogin(user)), or replace it with a non-sensitive status/logging
message (e.g., "user logged in") if you need an audit point; ensure
handleLogin(user) remains unchanged and no other code logs the user payload.
- Around line 11-15: The current logic in useAuth.js updates user role only when
userData.role exists, which can leave a stale role and mis-route authorization;
modify the update so that setUserRole is always called with userData.role when
present or a safe default (e.g., null or 'guest') when absent; specifically, in
the function handling userData (the block that calls setIsUserLoggedIn and
setIsOnboardingComplete), replace the conditional update of setUserRole with an
unconditional call that sets role to userData?.role ?? null (or your chosen
fail-closed default) so downstream checks in RoleProtectedRoute.js receive the
correct cleared value.

In `@frontend/src/services/auth.js`:
- Around line 39-43: The loginUser(username, password) signature was changed but
callers like the Login component still call loginUser(email, password); update
loginUser (in auth.js) to accept a neutral identifier (e.g., identifierOrEmail)
or support both names, and update or add an overload so it works with existing
callers; specifically, modify the loginUser function to accept (identifier,
password) or detect if the first arg is an email and forward it to
api.post("/auth/login", { username: identifier }) and then update Login.jsx
(which calls loginUser(email, password)) to pass its email prop unchanged, or
change all callers to pass username consistently so loginUser and callers
(loginUser, Login.jsx) match.
- Around line 15-21: The catch block in the onboarding call currently returns
error.response which makes the caller treat failures as resolved values; update
the catch in the async onboarding function (the try around
api.put(`/onboarding`, userData) in frontend/src/services/auth.js) to rethrow
the error (or return a rejected promise) instead of returning error.response so
callers like UserOnboarding.jsx can handle failures in their catch path;
optionally log the error before rethrowing for debugging.

---

Nitpick comments:
In `@frontend/src/Components/common/Sidebar.jsx`:
- Line 11: The hardcoded truncation visibleNavItems = navItems.slice(0, 14) in
Sidebar.jsx silently hides items; replace it with a configurable/dynamic
approach: either read a MAX_VISIBLE_NAV_ITEMS constant from config/env or a prop
(e.g., maxVisible) and use navItems.slice(0, maxVisible) or simply render all
navItems and add a "Show more" / collapsible behavior when length exceeds the
threshold; update any references to visibleNavItems accordingly (the navItems
array and visibleNavItems variable) and ensure unit/UI tests or prop types cover
the new maxVisible/config option.

In `@frontend/src/hooks/useAuth.js`:
- Around line 21-29: The code assumes fetchCredentials() returns an object with
a message property but only checks for a falsy response; update the logic in the
caller (around fetchCredentials, response, handleLogin) to verify the response
shape before calling handleLogin — e.g., ensure response && typeof
response.message === "object" (or expected primitive/fields) and that required
user fields exist; if the check fails, call setIsUserLoggedIn(false) and return,
otherwise extract the user and call handleLogin(user). Make this change where
response is used and reference the symbols fetchCredentials, response.message,
handleLogin, and setIsUserLoggedIn.

In `@frontend/src/services/auth.js`:
- Around line 24-35: The registerUser function currently returns the full Axios
response on success and returns error.response on failure, which mixes response
shapes; update registerUser to return a normalized shape consistent with other
auth services (e.g., return response.data on success and null or a standardized
error object on failure). Locate registerUser in frontend/src/services/auth.js
and change its success path to return response.data and its catch path to return
a consistent value (null or an object like { error: error.response?.data ||
error.message }) so callers receive a predictable contract.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 12a912d4-095e-4dbb-a3dd-d5076b10fd2d

📥 Commits

Reviewing files that changed from the base of the PR and between b726fc8 and 7263443.

📒 Files selected for processing (6)
  • frontend/src/Components/common/Sidebar.jsx
  • frontend/src/config/navbarConfig.js
  • frontend/src/hooks/useAuth.js
  • frontend/src/hooks/useSidebar.js
  • frontend/src/services/auth.js
  • frontend/src/utils/api.js
💤 Files with no reviewable changes (1)
  • frontend/src/hooks/useSidebar.js
✅ Files skipped from review due to trivial changes (1)
  • frontend/src/utils/api.js

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 14

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
backend/routes/profile.js (1)

110-111: ⚠️ Potential issue | 🟠 Major

Remove or sanitize debug logging of user data.

Logging updatedDetails directly can expose sensitive PII (email, phone, date of birth) in server logs. This poses a compliance/privacy risk (GDPR/CCPA). Either remove these logs or sanitize them to exclude sensitive fields.

Suggested fix
    const { userId, updatedDetails } = req.body;
-   console.log("Received userId:", userId);
-   console.log("Received updatedDetails:", updatedDetails);
+   console.log("Received profile update request for userId:", userId);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/routes/profile.js` around lines 110 - 111, Remove or sanitize the
debug console logs that print user data: locate the console.log calls
referencing userId and updatedDetails in the profile route handler (the lines
logging "Received userId:" and "Received updatedDetails:") and either delete the
updatedDetails log or replace it with a sanitized summary that omits PII (e.g.,
remove keys like email, phone, dob, ssn, password) and only logs non-sensitive
fields or a boolean/status; keep a minimal non-PII log for userId if needed, or
remove both logs entirely for production.
♻️ Duplicate comments (1)
frontend/src/Components/common/Sidebar.jsx (1)

78-92: ⚠️ Potential issue | 🟠 Major

Logout failure leaves user stuck with no retry option.

Good improvements: disabled={loggingOut} prevents double-clicks, and <Logout /> is now rendered outside the button. However, the core issue remains: the Logout component (per frontend/src/Components/Auth/Logout.jsx) does not accept any callback props. If the logout API call fails, loggingOut remains true, the button stays disabled, and the user cannot retry.

Recommended approach
  1. Update Logout.jsx to accept onError and optionally onComplete callbacks:
-const Logout = () => {
+const Logout = ({ onError, onComplete }) => {
   // ...
       } catch (error) {
         console.error("Logout failed:", error);
+        onError?.();
       }
+      // optionally call onComplete on success if needed
  1. Update Sidebar to handle the error and reset state:
-        {loggingOut && <Logout />}
+        {loggingOut && <Logout onError={() => setLoggingOut(false)} />}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/Components/common/Sidebar.jsx` around lines 78 - 92, The Logout
flow currently can leave the UI stuck because the Logout component (Logout)
never reports failures back to Sidebar; update the Logout component
(frontend/src/Components/Auth/Logout.jsx) to accept onError and onComplete
callback props and invoke onError(error) when the logout API fails and
onComplete() on any terminal path (success or final cleanup), and then update
Sidebar (component using setLoggingOut and loggingOut) to pass these callbacks:
pass onError={() => setLoggingOut(false)} (and optionally onComplete={() =>
setLoggingOut(false)}) so the button is re-enabled on failure or completion and
users can retry.
🧹 Nitpick comments (12)
backend/routes/profile.js (2)

139-159: Consider adding input validation for sensitive fields.

Fields like email and phone are updated without format validation. Invalid values could be stored in the database. Consider validating email format and phone number patterns before saving.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/routes/profile.js` around lines 139 - 159, The code updates sensitive
fields (name, email, phone, gender, date_of_birth, profilePic, cloudinaryUrl) on
the user.personal_info object without validating formats; add input validation
before assignment in the profile update handler: validate email using a robust
email check (e.g., validator.isEmail or a strict regex) and phone using a phone
pattern or library (e.g., validator.isMobilePhone with appropriate locale) and
reject or sanitize invalid inputs (return 400 with an error) rather than writing
them to user.personal_info; keep other fields (date_of_birth, gender) validated
for expected formats/values (e.g., ISO date, allowed gender values) before
assigning to user.personal_info.profilePic and user.personal_info.cloudinaryUrl
ensure they are valid URLs.

92-100: Consider returning a message when no photo exists to delete.

If cloudinaryUrl is empty/falsy, the route silently returns the current profilePic without indicating that no deletion occurred. Consider returning a different status or message to inform the client.

Suggested improvement
    // Delete from Cloudinary if exists
    if (user.personal_info.cloudinaryUrl) {
      await cloudinary.uploader.destroy(user.personal_info.cloudinaryUrl);
      user.personal_info.profilePic = "https://www.gravatar.com/avatar/?d=mp"; // Default photo
      user.personal_info.cloudinaryUrl = "";
      await user.save();
+    } else {
+      return res.status(200).json({ 
+        message: "No custom photo to delete",
+        profilePic: user.personal_info.profilePic 
+      });
    }

    res.json({ profilePic: user.personal_info.profilePic });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/routes/profile.js` around lines 92 - 100, The route currently
silently returns the profilePic when user.personal_info.cloudinaryUrl is falsy;
add an explicit check before calling cloudinary.uploader.destroy and return a
clear status and message (e.g., res.status(404).json({ message: "No profile
photo to delete", profilePic: user.personal_info.profilePic })) if no
cloudinaryUrl exists; otherwise continue to call cloudinary.uploader.destroy,
set user.personal_info.profilePic to the default, clear
user.personal_info.cloudinaryUrl and await user.save() as currently implemented.
frontend/src/Components/common/Sidebar.jsx (1)

11-11: Consider extracting the magic number 14 into a named constant.

The hardcoded limit of 14 items is not immediately self-documenting. A named constant would clarify intent and make future adjustments easier.

+const MAX_VISIBLE_NAV_ITEMS = 14;
+
 const Sidebar = () => {
   const [loggingOut, setLoggingOut] = useState(false);
   const { navItems, selected, setSelected, isCollapsed, setIsCollapsed } = useSidebar();

-  const visibleNavItems = navItems.slice(0, 14);
+  const visibleNavItems = navItems.slice(0, MAX_VISIBLE_NAV_ITEMS);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/Components/common/Sidebar.jsx` at line 11, The slice limit 14 in
the visibleNavItems assignment is a magic number; extract it into a descriptive
constant (e.g., MAX_VISIBLE_NAV_ITEMS) and use that constant in the expression
that creates visibleNavItems (navItems.slice(0, MAX_VISIBLE_NAV_ITEMS)) so the
intent is clear and future changes are easier; add the constant near the top of
Sidebar.jsx or next to navItems so it’s easy to find.
frontend/src/services/auth.js (2)

1-3: Remove unused imports.

axios is commented out and toast is imported but never used in this file.

♻️ Proposed fix
-//import axios from "axios";
 import api from "../utils/api";
-import { toast } from "react-toastify";
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/services/auth.js` around lines 1 - 3, Remove the unused imports
in auth.js: delete the commented-out axios import line (axios) and remove the
unused `toast` import from "react-toastify" so only the actual `api` import
remains; ensure no other references to `axios` or `toast` exist in functions in
this file (e.g., any auth-related functions) before committing.

34-34: Remove commented-out debug log.

♻️ Proposed fix
   } catch (error) {
-    //console.error("Error obj is:",error.response);
     throw error
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/services/auth.js` at line 34, Remove the leftover commented
debug log (the commented-out console.error("Error obj is:",error.response);)
from frontend/src/services/auth.js; locate the commented line in the relevant
auth function (e.g., any error handling block such as login or request error
handlers) and delete it so no commented debug statements remain, and run
lint/format to ensure the file meets project style rules.
frontend/src/Components/Requests/Requests.jsx (2)

104-104: Missing navigate in useEffect dependency array.

The navigate function is used inside the effect but not listed in dependencies. While navigate from react-router is typically stable, ESLint rules for exhaustive deps would flag this.

♻️ Proposed fix
-  }, [isUserLoggedIn]);
+  }, [isUserLoggedIn, navigate]);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/Components/Requests/Requests.jsx` at line 104, The effect in the
Requests component uses the navigate function but the dependency array only
includes isUserLoggedIn, which can trigger ESLint exhaustive-deps warnings;
update the useEffect dependency array in Requests.jsx to include navigate (e.g.,
useEffect(..., [isUserLoggedIn, navigate])) or, if navigate is intentionally
stable, explicitly document and silence the lint rule with a comment, ensuring
the reference to navigate in the effect is handled consistently.

1-1: Unused import: OctagonAlert.

OctagonAlert is imported but never used.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/Components/Requests/Requests.jsx` at line 1, The import list in
Requests.jsx includes an unused symbol OctagonAlert; remove OctagonAlert from
the named import list (import { Search, OctagonAlert, FileText } from
"lucide-react") or replace it by using OctagonAlert where intended to avoid the
unused-import lint error—update the import to import only Search and FileText
(or add the component usage) and run the linter to confirm the warning is
resolved.
frontend/src/Components/Requests/viewModal.jsx (1)

1-2: Remove unnecessary blank lines at file start.

The file begins with two empty lines before the imports.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/Components/Requests/viewModal.jsx` around lines 1 - 2, Remove
the two leading blank lines at the top of
frontend/src/Components/Requests/viewModal.jsx so the file starts immediately
with its first import statement (e.g., import React.../other imports); ensure
there are no empty lines before the import block and save the file so the top of
the file begins with the import declarations.
frontend/src/Components/Requests/ui.jsx (1)

34-47: Consider adding a fallback for invalid color props.

If color is not one of the defined keys (amber, red, green), styles[color] will be undefined, resulting in no styling applied.

♻️ Proposed fix
 export const Pill = ({ label, color = "amber" }) => {
     const styles = {
         amber: "bg-yellow-100 text-yellow-800",
         red: "bg-red-100 text-red-700",
         green: "bg-green-100 text-green-700 ",
     };

     return (
-        <span className={`inline-flex items-center gap-1 px-3 py-1 rounded-full text-xs tracking-wide font-semibold ${styles[color]}`}
+        <span className={`inline-flex items-center gap-1 px-3 py-1 rounded-full text-xs tracking-wide font-semibold ${styles[color] || styles.amber}`}
         >
             {label}
         </span>
     );
 };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/Components/Requests/ui.jsx` around lines 34 - 47, Pill component
uses styles[color] directly so an invalid color prop yields undefined classes;
update Pill to validate or fallback by checking if color is a key in the styles
object (e.g., use styles[color] || styles.amber) or normalize the color before
use so the span always receives a valid class string; reference the Pill
function and the styles object to implement the fallback.
frontend/src/Components/Requests/editModal.jsx (1)

177-190: Save action proceeds regardless of validation or async result.

The Save button immediately calls onClose() after onSave(form). If onSave were async or could fail, the modal would close before the operation completes. Consider awaiting or confirming success before closing.

♻️ Proposed fix for safer save handling
-          <button onClick={() => { onSave(form); onClose(); }} style={{
+          <button onClick={async () => { 
+            try {
+              await onSave(form); 
+              onClose(); 
+            } catch (e) {
+              // handle error - modal stays open
+            }
+          }} style={{
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/Components/Requests/editModal.jsx` around lines 177 - 190, The
Save button currently calls onSave(form) and immediately onClose(), which closes
the modal even if onSave is async or fails; change the button handler to an
async handler that awaits onSave(form) (or checks its returned Promise/result)
and only call onClose() after a successful save, handle and surface errors
(e.g., set a local saving/error state to disable the button and show feedback),
and ensure you reference the click handler on the Save button, the onSave(form)
call and onClose() invocation when making these changes.
frontend/src/Components/Requests/Card.jsx (1)

1-1: Unused import: useState.

useState is imported but never used in this component.

♻️ Proposed fix
-import { useState } from "react";
 import { useAdminContext } from "../../context/AdminContext";
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/Components/Requests/Card.jsx` at line 1, The import of useState
at the top of frontend/src/Components/Requests/Card.jsx is unused; remove the
named import useState from the import statement (or remove the entire import if
nothing else is imported) so the module no longer imports unused symbols and
ESLint warnings are resolved.
frontend/src/hooks/useAuth.js (1)

28-31: Remove commented-out debug logs.

These commented console.log statements are dead code and should be removed for cleanliness.

♻️ Proposed fix
         const user = response.message;
-        //console.log("User is:", user);
         handleLogin(user);
-          //console.log("User role:", user.role);
-          //console.log("Onboarding complete:", user.onboardingComplete);
       } catch (error) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/hooks/useAuth.js` around lines 28 - 31, Remove the dead
commented debug logs in useAuth (the commented console.log lines that reference
"User is:", "User role:", and "Onboarding complete:") so the handleLogin(user)
call stands alone; simply delete those commented lines to clean up the hook and
avoid leaving commented-out console.log statements in the useAuth.js
implementation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@backend/index.js`:
- Line 42: The app currently uses process.env.SESSION_SECRET (referenced as
secret: process.env.SESSION_SECRET) without validating it; add a startup check
immediately after require("dotenv").config() to ensure
process.env.SESSION_SECRET is set and throw a clear Error (e.g., "SESSION_SECRET
environment variable is required") if missing so the process fails fast and
avoids running with an undefined session secret.
- Around line 89-95: The current startup IIFE awaits connectDB() without
handling errors, so a rejection will become an unhandled promise rejection and
the server may still start; wrap the connectDB() call in a try/catch inside the
async IIFE (or before calling app.listen) and on catch call console.error with
the error and exit with process.exit(1) so the server doesn't start on DB
failure; also consider adding a process.on('unhandledRejection', ...) handler to
log and exit for any stray promise rejections.

In `@backend/models/certificateSchema.js`:
- Around line 6-9: The certificateSchema's eventIid field uses the wrong
Mongoose ref ("eventSchema") causing populate to return null; update the ref for
eventIid (the field defined with mongoose.Schema.Types.ObjectId named eventIid
in certificateSchema) to match the model name "Event" (the string used in
mongoose.model("Event", ...)) so populate('eventIid') works correctly.

In `@frontend/src/Components/common/Sidebar.jsx`:
- Around line 61-62: The conditional class strings in Sidebar.jsx use the old
Tailwind important prefix syntax (!rounded-2xl, !rounded-xl) which is
incompatible with Tailwind v4; update those class names used in the JSX
conditional (the ternary that returns "bg-white text-black font-medium
!rounded-2xl mb-1" or "text-zinc-400 hover:text-white hover:bg-zinc-600
!rounded-xl") to the v4 suffix form by moving the exclamation mark to the end of
the utility names (e.g., "rounded-2xl!" and "rounded-xl!") so the !important
modifier is applied.

In `@frontend/src/Components/Requests/Card.jsx`:
- Around line 104-105: The conditional rendering in Card.jsx uses
userRole.startsWith("GENSEC") which will throw if userRole is null/undefined;
update the expression to guard against null (e.g., use optional chaining
userRole?.startsWith("GENSEC") or a boolean check like (userRole &&
userRole.startsWith("GENSEC"))) so the overall condition becomes (userRole ===
"PRESIDENT" || userRole?.startsWith("GENSEC")) to prevent runtime TypeError
during render.
- Line 52: The inline style for the card border in the Requests Card component
has a CSS syntax typo: change the borderBottom value in the JSX (style={{
borderBottom: last ? "none" : "2px solidrgb(198, 194, 150)" }}) to include a
space before the rgb function so it reads "2px solid rgb(198, 194, 150)"; update
the expression in Card (Requests/RequestsCard component) accordingly to ensure
the border renders correctly.

In `@frontend/src/Components/Requests/editModal.jsx`:
- Around line 127-132: The number input's onChange currently uses
set("students") directly so e.target.value (a string) gets stored, changing
form.students from number to string; update the input's onChange to convert
e.target.value to a numeric type before calling the setter produced by
set("students") (e.g. parseInt/Number and handle empty string/null cases) so
form.students remains a number; locate the input element in editModal.jsx and
adjust the onChange wrapper around set("students") accordingly.

In `@frontend/src/Components/Requests/Requests.jsx`:
- Around line 42-49: The loop in requests.forEach is overwriting total instead
of accumulating approved student counts: replace the assignment total =
approved*req.students with an accumulation (e.g., total += req.students) so
total sums req.students for each approved request; ensure approved and total are
initialized before the loop and leave other branches (Rejected, pending)
unchanged.
- Line 14: The component Requests.jsx is incorrectly destructuring requestStatus
and setRequestStatus from useRequest(); instead, update the destructuring to
pull the individual values and setters provided by RequestContext (pending,
approved, rejected, total, setPending, setApproved, setRejected, setTotal) and
then replace any uses of requestStatus.pending / requestStatus.approved etc.
with the corresponding variables (pending, approved, rejected, total) and
replace calls to setRequestStatus(...) with the specific setters
(setPending(...), setApproved(...), setRejected(...), setTotal(...)); also
update the useEffect and any handlers in the Requests component to call those
individual setters instead of setRequestStatus so the component matches
RequestContext's API.

In `@frontend/src/Components/Requests/viewModal.jsx`:
- Around line 77-87: The close button in viewModal.jsx uses a dynamic Tailwind
class text-[${C.warmGray}] which Tailwind can't resolve at runtime; update the
button to apply the color via inline style or a CSS class instead: remove
text-[${C.warmGray}] and add a style prop like style={{ color: C.warmGray }} (or
compute a static Tailwind class if a known token exists), ensuring the X icon
(component X) inherits the color or receives the same style; keep the onClick
handler (onClose) and other classes untouched.
- Around line 126-141: The footer Close button in viewModal.jsx uses dynamic
Tailwind bracket classes (bg-[${C.text}] and text-[${C.cream}]) which won't be
processed; replace those with regular Tailwind classes or set the colors via
inline style: remove bg-[${C.text}] and text-[${C.cream}] from className and add
style entries for backgroundColor and color (e.g., add backgroundColor: C.text
and color: C.cream) while preserving the rest of the className and existing
style (fontWeight, fontSize); update the button that uses onClose accordingly so
the visual colors are applied at runtime.
- Around line 69-75: The header div uses a dynamic Tailwind class
`border-[${C.borderStrong}]` which Tailwind can't resolve at runtime; remove
that from the className and add an inline style to set the border color (e.g.
keep `border-b` in className and add style={{ borderColor: C.borderStrong }}).
Edit the header div in viewModal.jsx (the top header div JSX) to remove
`border-[${C.borderStrong}]` and add the style prop so the border color is
applied via the C.borderStrong value.
- Around line 57-67: The modal container in viewModal.jsx uses dynamic Tailwind
bracket classes bg-[${C.cream}] and border-[${C.borderStrong}] which won't be
picked up by Tailwind's purge; remove those dynamic bracket classes from the
template string in the div's className and instead set the colors via the inline
style object (e.g., add backgroundColor: C.cream and borderColor: C.borderStrong
to the existing style prop), keeping the rest of the static Tailwind classes
(w-[520px], rounded-[20px], overflow-hidden, border-[1.5px], shadow-..., etc.)
intact so Tailwind can detect them. Ensure you update the className in the same
div element in viewModal.jsx and keep the existing fontFamily style.
- Around line 19-52: The InfoTile component uses dynamic Tailwind class names
(e.g., bg-[${C.white}], text-[${C.text}], border-[${C.border}]) which Tailwind
won't detect; update InfoTile to remove those dynamic bracket classes and pass
the colors via inline style props instead (set style={{ backgroundColor:
C.white, color: C.text, borderColor: C.border }} on the outer div and/or inner
spans) while keeping the static Tailwind utility classes (rounded-[14px],
px-[20px], py-[16px], flex, etc.); ensure Icon usage (Icon size/ strokeWidth)
and the wide conditional class (col-span-full) remain unchanged.

---

Outside diff comments:
In `@backend/routes/profile.js`:
- Around line 110-111: Remove or sanitize the debug console logs that print user
data: locate the console.log calls referencing userId and updatedDetails in the
profile route handler (the lines logging "Received userId:" and "Received
updatedDetails:") and either delete the updatedDetails log or replace it with a
sanitized summary that omits PII (e.g., remove keys like email, phone, dob, ssn,
password) and only logs non-sensitive fields or a boolean/status; keep a minimal
non-PII log for userId if needed, or remove both logs entirely for production.

---

Duplicate comments:
In `@frontend/src/Components/common/Sidebar.jsx`:
- Around line 78-92: The Logout flow currently can leave the UI stuck because
the Logout component (Logout) never reports failures back to Sidebar; update the
Logout component (frontend/src/Components/Auth/Logout.jsx) to accept onError and
onComplete callback props and invoke onError(error) when the logout API fails
and onComplete() on any terminal path (success or final cleanup), and then
update Sidebar (component using setLoggingOut and loggingOut) to pass these
callbacks: pass onError={() => setLoggingOut(false)} (and optionally
onComplete={() => setLoggingOut(false)}) so the button is re-enabled on failure
or completion and users can retry.

---

Nitpick comments:
In `@backend/routes/profile.js`:
- Around line 139-159: The code updates sensitive fields (name, email, phone,
gender, date_of_birth, profilePic, cloudinaryUrl) on the user.personal_info
object without validating formats; add input validation before assignment in the
profile update handler: validate email using a robust email check (e.g.,
validator.isEmail or a strict regex) and phone using a phone pattern or library
(e.g., validator.isMobilePhone with appropriate locale) and reject or sanitize
invalid inputs (return 400 with an error) rather than writing them to
user.personal_info; keep other fields (date_of_birth, gender) validated for
expected formats/values (e.g., ISO date, allowed gender values) before assigning
to user.personal_info.profilePic and user.personal_info.cloudinaryUrl ensure
they are valid URLs.
- Around line 92-100: The route currently silently returns the profilePic when
user.personal_info.cloudinaryUrl is falsy; add an explicit check before calling
cloudinary.uploader.destroy and return a clear status and message (e.g.,
res.status(404).json({ message: "No profile photo to delete", profilePic:
user.personal_info.profilePic })) if no cloudinaryUrl exists; otherwise continue
to call cloudinary.uploader.destroy, set user.personal_info.profilePic to the
default, clear user.personal_info.cloudinaryUrl and await user.save() as
currently implemented.

In `@frontend/src/Components/common/Sidebar.jsx`:
- Line 11: The slice limit 14 in the visibleNavItems assignment is a magic
number; extract it into a descriptive constant (e.g., MAX_VISIBLE_NAV_ITEMS) and
use that constant in the expression that creates visibleNavItems
(navItems.slice(0, MAX_VISIBLE_NAV_ITEMS)) so the intent is clear and future
changes are easier; add the constant near the top of Sidebar.jsx or next to
navItems so it’s easy to find.

In `@frontend/src/Components/Requests/Card.jsx`:
- Line 1: The import of useState at the top of
frontend/src/Components/Requests/Card.jsx is unused; remove the named import
useState from the import statement (or remove the entire import if nothing else
is imported) so the module no longer imports unused symbols and ESLint warnings
are resolved.

In `@frontend/src/Components/Requests/editModal.jsx`:
- Around line 177-190: The Save button currently calls onSave(form) and
immediately onClose(), which closes the modal even if onSave is async or fails;
change the button handler to an async handler that awaits onSave(form) (or
checks its returned Promise/result) and only call onClose() after a successful
save, handle and surface errors (e.g., set a local saving/error state to disable
the button and show feedback), and ensure you reference the click handler on the
Save button, the onSave(form) call and onClose() invocation when making these
changes.

In `@frontend/src/Components/Requests/Requests.jsx`:
- Line 104: The effect in the Requests component uses the navigate function but
the dependency array only includes isUserLoggedIn, which can trigger ESLint
exhaustive-deps warnings; update the useEffect dependency array in Requests.jsx
to include navigate (e.g., useEffect(..., [isUserLoggedIn, navigate])) or, if
navigate is intentionally stable, explicitly document and silence the lint rule
with a comment, ensuring the reference to navigate in the effect is handled
consistently.
- Line 1: The import list in Requests.jsx includes an unused symbol
OctagonAlert; remove OctagonAlert from the named import list (import { Search,
OctagonAlert, FileText } from "lucide-react") or replace it by using
OctagonAlert where intended to avoid the unused-import lint error—update the
import to import only Search and FileText (or add the component usage) and run
the linter to confirm the warning is resolved.

In `@frontend/src/Components/Requests/ui.jsx`:
- Around line 34-47: Pill component uses styles[color] directly so an invalid
color prop yields undefined classes; update Pill to validate or fallback by
checking if color is a key in the styles object (e.g., use styles[color] ||
styles.amber) or normalize the color before use so the span always receives a
valid class string; reference the Pill function and the styles object to
implement the fallback.

In `@frontend/src/Components/Requests/viewModal.jsx`:
- Around line 1-2: Remove the two leading blank lines at the top of
frontend/src/Components/Requests/viewModal.jsx so the file starts immediately
with its first import statement (e.g., import React.../other imports); ensure
there are no empty lines before the import block and save the file so the top of
the file begins with the import declarations.

In `@frontend/src/hooks/useAuth.js`:
- Around line 28-31: Remove the dead commented debug logs in useAuth (the
commented console.log lines that reference "User is:", "User role:", and
"Onboarding complete:") so the handleLogin(user) call stands alone; simply
delete those commented lines to clean up the hook and avoid leaving
commented-out console.log statements in the useAuth.js implementation.

In `@frontend/src/services/auth.js`:
- Around line 1-3: Remove the unused imports in auth.js: delete the
commented-out axios import line (axios) and remove the unused `toast` import
from "react-toastify" so only the actual `api` import remains; ensure no other
references to `axios` or `toast` exist in functions in this file (e.g., any
auth-related functions) before committing.
- Line 34: Remove the leftover commented debug log (the commented-out
console.error("Error obj is:",error.response);) from
frontend/src/services/auth.js; locate the commented line in the relevant auth
function (e.g., any error handling block such as login or request error
handlers) and delete it so no commented debug statements remain, and run
lint/format to ensure the file meets project style rules.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 955cdec8-cf7f-4414-bf2e-4de706683fb5

📥 Commits

Reviewing files that changed from the base of the PR and between 7263443 and 7045720.

📒 Files selected for processing (15)
  • backend/index.js
  • backend/models/certificateSchema.js
  • backend/routes/analytics.js
  • backend/routes/orgUnit.js
  • backend/routes/profile.js
  • backend/utils/authValidate.js
  • frontend/src/Components/Requests/Card.jsx
  • frontend/src/Components/Requests/Requests.jsx
  • frontend/src/Components/Requests/editModal.jsx
  • frontend/src/Components/Requests/ui.jsx
  • frontend/src/Components/Requests/viewModal.jsx
  • frontend/src/Components/common/Sidebar.jsx
  • frontend/src/hooks/useAuth.js
  • frontend/src/pages/requestsPage.jsx
  • frontend/src/services/auth.js
🚧 Files skipped from review as they are similar to previous changes (3)
  • backend/routes/analytics.js
  • backend/utils/authValidate.js
  • backend/routes/orgUnit.js

Comment on lines +6 to +9
eventIid: {
type: mongoose.Schema.Types.ObjectId,
ref: "eventSchema",
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

find . -name "eventSchema.js" -o -name "event*.js" | grep -i schema | head -20

Repository: OpenLake/Student_Database_COSA

Length of output: 105


🏁 Script executed:

rg -n "mongoose\.model" --glob "**/eventSchema.js" -A 1

Repository: OpenLake/Student_Database_COSA

Length of output: 217


🏁 Script executed:

cat -n backend/models/certificateSchema.js | head -20

Repository: OpenLake/Student_Database_COSA

Length of output: 783


Incorrect Mongoose ref value — "eventSchema" should be "Event".

Mongoose ref must match the first argument passed to mongoose.model(). The Event model is registered as mongoose.model("Event", ...) in eventSchema.js (line 110). Using "eventSchema" (the schema variable name) instead will cause .populate('eventIid') to silently return null.

Fix
    eventIid: {
      type: mongoose.Schema.Types.ObjectId,
-     ref: "eventSchema",
+     ref: "Event",
    },
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/models/certificateSchema.js` around lines 6 - 9, The
certificateSchema's eventIid field uses the wrong Mongoose ref ("eventSchema")
causing populate to return null; update the ref for eventIid (the field defined
with mongoose.Schema.Types.ObjectId named eventIid in certificateSchema) to
match the model name "Event" (the string used in mongoose.model("Event", ...))
so populate('eventIid') works correctly.

Comment on lines +61 to +62
? "bg-white text-black font-medium !rounded-2xl mb-1"
: "text-zinc-400 hover:text-white hover:bg-zinc-600 !rounded-xl"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check Tailwind CSS version and configuration style

echo "=== Checking Tailwind version in package.json ==="
if [ -f "package.json" ]; then
  jq -r '.dependencies.tailwindcss // .devDependencies.tailwindcss // "not found"' package.json 2>/dev/null
else
  echo "package.json not found"
fi

echo -e "\n=== Checking for Tailwind config files ==="
find . -maxdepth 2 -type f -name "tailwind.config.*" 2>/dev/null | head -10

echo -e "\n=== Checking current Sidebar.jsx for context ==="
if [ -f "frontend/src/Components/common/Sidebar.jsx" ]; then
  sed -n '55,70p' frontend/src/Components/common/Sidebar.jsx
else
  echo "File not found"
fi

Repository: OpenLake/Student_Database_COSA

Length of output: 1025


🏁 Script executed:

#!/bin/bash
# Search for package.json throughout the repository
echo "=== Finding package.json files ==="
find . -name "package.json" -type f 2>/dev/null

echo -e "\n=== Finding tailwind.config files ==="
find . -name "tailwind.config*" -type f 2>/dev/null

echo -e "\n=== Checking for tsconfig/jsconfig in frontend ==="
find . -path "*/frontend/*" -name "tsconfig.json" -o -name "jsconfig.json" 2>/dev/null | head -5

Repository: OpenLake/Student_Database_COSA

Length of output: 246


🏁 Script executed:

#!/bin/bash
# Check frontend package.json for Tailwind version
echo "=== Checking frontend/package.json for Tailwind ==="
jq '.dependencies.tailwindcss, .devDependencies.tailwindcss' frontend/package.json 2>/dev/null

echo -e "\n=== Checking for CSS files with Tailwind imports ==="
rg '@import.*tailwindcss|@tailwind' --type css frontend/ 2>/dev/null | head -10

echo -e "\n=== Looking for postcss config ==="
find ./frontend -maxdepth 2 -name "postcss.config.*" -o -name "tailwind.config.*" 2>/dev/null

Repository: OpenLake/Student_Database_COSA

Length of output: 447


Update important modifier syntax for Tailwind v4.

The project uses Tailwind CSS v4.0.3. In v4, the important modifier syntax changed from prefix (!rounded-2xl) to suffix (rounded-2xl!). Lines 61-62 use the old v3 syntax, which will not apply !important in v4.

Fix
                 ${
                   selected === item.key
-                    ? "bg-white text-black font-medium !rounded-2xl mb-1"
-                    : "text-zinc-400 hover:text-white hover:bg-zinc-600 !rounded-xl"
+                    ? "bg-white text-black font-medium rounded-2xl! mb-1"
+                    : "text-zinc-400 hover:text-white hover:bg-zinc-600 rounded-xl!"
                 }`}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/Components/common/Sidebar.jsx` around lines 61 - 62, The
conditional class strings in Sidebar.jsx use the old Tailwind important prefix
syntax (!rounded-2xl, !rounded-xl) which is incompatible with Tailwind v4;
update those class names used in the JSX conditional (the ternary that returns
"bg-white text-black font-medium !rounded-2xl mb-1" or "text-zinc-400
hover:text-white hover:bg-zinc-600 !rounded-xl") to the v4 suffix form by moving
the exclamation mark to the end of the utility names (e.g., "rounded-2xl!" and
"rounded-xl!") so the !important modifier is applied.

<tr
key={req.id}
className="group hover:bg-amber-100/60 transition-colors duration-150"
style={{ borderBottom: last ? "none" : "2px solidrgb(198, 194, 150)" }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

CSS syntax error: missing space in border value.

"solidrgb(198, 194, 150)" should be "solid rgb(198, 194, 150)". This will cause the border to not render correctly.

🐛 Proposed fix
-                  style={{ borderBottom: last ? "none" : "2px solidrgb(198, 194, 150)" }}
+                  style={{ borderBottom: last ? "none" : "2px solid rgb(198, 194, 150)" }}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
style={{ borderBottom: last ? "none" : "2px solidrgb(198, 194, 150)" }}
style={{ borderBottom: last ? "none" : "2px solid rgb(198, 194, 150)" }}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/Components/Requests/Card.jsx` at line 52, The inline style for
the card border in the Requests Card component has a CSS syntax typo: change the
borderBottom value in the JSX (style={{ borderBottom: last ? "none" : "2px
solidrgb(198, 194, 150)" }}) to include a space before the rgb function so it
reads "2px solid rgb(198, 194, 150)"; update the expression in Card
(Requests/RequestsCard component) accordingly to ensure the border renders
correctly.

Comment on lines +19 to +52
const InfoTile = ({ icon: Icon, label, value, wide }) => (
<div
className={`
${wide ? "col-span-full" : ""}
rounded-[14px]
px-[20px] py-[16px]
flex flex-col gap-[6px]
border
bg-[${C.white}]
border-[${C.border}]
`}
>
<div
className={`
flex items-center gap-[7px]
text-[${C.warmGray}]
`}
>
<Icon size={15} strokeWidth={2} />
<span className="text-[11px] font-semibold tracking-[0.08em] uppercase">
{label}
</span>
</div>

<span
className={`
text-[20px] font-bold tracking-[-0.01em]
text-[${C.text}]
`}
>
{value}
</span>
</div>
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Dynamic Tailwind class names will not work at build time.

Tailwind CSS purges unused classes at build time by scanning for complete class strings. Dynamic constructions like bg-[${C.white}] or text-[${C.text}] will not be detected and the styles won't be applied.

Either use inline styles consistently (as done in editModal.jsx) or use static Tailwind classes.

🛠️ Proposed fix using inline styles
 const InfoTile = ({ icon: Icon, label, value, wide }) => (
   <div
-    className={`
-      ${wide ? "col-span-full" : ""}
-      rounded-[14px]
-      px-[20px] py-[16px]
-      flex flex-col gap-[6px]
-      border
-      bg-[${C.white}]
-      border-[${C.border}]
-    `}
+    className={`${wide ? "col-span-full" : ""} rounded-[14px] flex flex-col gap-[6px] border`}
+    style={{
+      padding: "16px 20px",
+      background: C.white,
+      borderColor: C.border,
+    }}
   >
     <div
-      className={`
-        flex items-center gap-[7px]
-        text-[${C.warmGray}]
-      `}
+      className="flex items-center gap-[7px]"
+      style={{ color: C.warmGray }}
     >
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/Components/Requests/viewModal.jsx` around lines 19 - 52, The
InfoTile component uses dynamic Tailwind class names (e.g., bg-[${C.white}],
text-[${C.text}], border-[${C.border}]) which Tailwind won't detect; update
InfoTile to remove those dynamic bracket classes and pass the colors via inline
style props instead (set style={{ backgroundColor: C.white, color: C.text,
borderColor: C.border }} on the outer div and/or inner spans) while keeping the
static Tailwind utility classes (rounded-[14px], px-[20px], py-[16px], flex,
etc.); ensure Icon usage (Icon size/ strokeWidth) and the wide conditional class
(col-span-full) remain unchanged.

Comment on lines +57 to +67
<div className={`
w-[520px]
rounded-[20px]
overflow-hidden
border-[1.5px]
shadow-[0_24px_60px_rgba(30,26,10,0.28)]
bg-[${C.cream}]
border-[${C.borderStrong}]
`} style={{
fontFamily: "'DM Sans', sans-serif",
}}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Same Tailwind dynamic class issue in modal container.

bg-[${C.cream}] and border-[${C.borderStrong}] won't be detected by Tailwind's purge. Use inline styles for dynamic color values.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/Components/Requests/viewModal.jsx` around lines 57 - 67, The
modal container in viewModal.jsx uses dynamic Tailwind bracket classes
bg-[${C.cream}] and border-[${C.borderStrong}] which won't be picked up by
Tailwind's purge; remove those dynamic bracket classes from the template string
in the div's className and instead set the colors via the inline style object
(e.g., add backgroundColor: C.cream and borderColor: C.borderStrong to the
existing style prop), keeping the rest of the static Tailwind classes
(w-[520px], rounded-[20px], overflow-hidden, border-[1.5px], shadow-..., etc.)
intact so Tailwind can detect them. Ensure you update the className in the same
div element in viewModal.jsx and keep the existing fontFamily style.

Comment on lines +69 to +75
<div className={`
bg-[linear-gradient(135deg,#F7F0A8_0%,#EDE090_100%)]
px-[28px] pt-[22px] pb-[18px]
border-b
relative
border-[${C.borderStrong}]
`}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Same Tailwind dynamic class issue in header.

border-[${C.borderStrong}] won't work. Convert to inline style.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/Components/Requests/viewModal.jsx` around lines 69 - 75, The
header div uses a dynamic Tailwind class `border-[${C.borderStrong}]` which
Tailwind can't resolve at runtime; remove that from the className and add an
inline style to set the border color (e.g. keep `border-b` in className and add
style={{ borderColor: C.borderStrong }}). Edit the header div in viewModal.jsx
(the top header div JSX) to remove `border-[${C.borderStrong}]` and add the
style prop so the border color is applied via the C.borderStrong value.

Comment on lines +77 to +87
<button onClick={onClose} className={`
absolute top-[16px] right-[16px]
bg-[rgba(0,0,0,0.08)]
!rounded-md
p-[6px]
flex items-center
cursor-pointer
text-[${C.warmGray}]
`}>
<X size={15} />
</button>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Same Tailwind dynamic class issue in close button.

text-[${C.warmGray}] won't work at runtime.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/Components/Requests/viewModal.jsx` around lines 77 - 87, The
close button in viewModal.jsx uses a dynamic Tailwind class text-[${C.warmGray}]
which Tailwind can't resolve at runtime; update the button to apply the color
via inline style or a CSS class instead: remove text-[${C.warmGray}] and add a
style prop like style={{ color: C.warmGray }} (or compute a static Tailwind
class if a known token exists), ensuring the X icon (component X) inherits the
color or receives the same style; keep the onClick handler (onClose) and other
classes untouched.

Comment on lines +126 to +141
<button onClick={onClose}
className={`
px-[28px] py-[10px]
!rounded-md
border-none
cursor-pointer
tracking-[0.02em]
bg-[${C.text}]
text-[${C.cream}]
`}
style={{
fontWeight: 600, fontSize: 14,
}}
>
Close
</button>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Same Tailwind dynamic class issue in footer button.

bg-[${C.text}] and text-[${C.cream}] won't be applied.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/Components/Requests/viewModal.jsx` around lines 126 - 141, The
footer Close button in viewModal.jsx uses dynamic Tailwind bracket classes
(bg-[${C.text}] and text-[${C.cream}]) which won't be processed; replace those
with regular Tailwind classes or set the colors via inline style: remove
bg-[${C.text}] and text-[${C.cream}] from className and add style entries for
backgroundColor and color (e.g., add backgroundColor: C.text and color: C.cream)
while preserving the rest of the className and existing style (fontWeight,
fontSize); update the button that uses onClose accordingly so the visual colors
are applied at runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant