Skip to content

Polish/polish codebase - #18

Merged
arxja merged 13 commits into
mainfrom
polish/polish-codebase
Jul 27, 2026
Merged

Polish/polish codebase#18
arxja merged 13 commits into
mainfrom
polish/polish-codebase

Conversation

@arxja

@arxja arxja commented Jul 27, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Added sign-out functionality that clears the authentication session.
    • Added authenticated user status checks and improved handling of invalid or expired sessions.
    • Redesigned navigation with a logo, links, responsive scroll behavior, and login/user controls.
  • Bug Fixes

    • Updated authentication flows to use consistent sign-in, sign-up, and sign-out routes.
    • Improved database connection handling during authentication requests.
    • Normalized email addresses during registration and sign-in checks.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@arxja, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 54 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 32aa74e8-1a2c-4823-bd70-fec7043e3117

📥 Commits

Reviewing files that changed from the base of the PR and between 4fa06a1 and 4e77fee.

📒 Files selected for processing (2)
  • app/api/auth/me/route.ts
  • proxy.ts
📝 Walkthrough

Walkthrough

Authentication routes were moved or added under /api/auth, JWT configuration was updated, useAuth now uses the new endpoints, and the navbar was decomposed into reusable layout and feature components.

Changes

Authentication route handlers

Layer / File(s) Summary
Authentication route handlers
app/api/auth/*, lib/auth/jwt.ts, __tests__/unit/auth-routes.test.ts
Added the authenticated user endpoint and sign-out route, connected sign-in and sign-up flows to the database, updated JWT secret handling and expiration processing, and added sign-up route tests.

Client auth endpoint migration

Layer / File(s) Summary
Client auth endpoint migration
hooks/useAuth.ts, proxy.ts
Updated authentication requests to /api/auth/*, added explicit response handling during auth initialization, and updated the public route allowlist.

Navbar component composition

Layer / File(s) Summary
Navbar component composition
components/layout/Navbar.tsx, components/features/navbar/*, app/(root)/layout.tsx, components/Navbar.tsx
Replaced the former navbar with composed logo, links, user, scroll-control, and authentication components, and updated the root layout import.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Browser
  participant useAuth
  participant AuthMeRoute
  participant verifyJWT
  participant dashboardUserModel
  Browser->>useAuth: initialize authentication
  useAuth->>AuthMeRoute: GET /api/auth/me
  AuthMeRoute->>verifyJWT: verify auth token
  AuthMeRoute->>dashboardUserModel: find user by token userId
  dashboardUserModel-->>AuthMeRoute: user data without passwordHash
  AuthMeRoute-->>useAuth: authentication response
  useAuth-->>Browser: render authenticated or Login state
Loading
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is vague and generic; it doesn't describe the auth, navbar, and route changes in the PR. Rename it to reflect the main change, such as adding auth routes and the new navbar/layout refactor.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch polish/polish-codebase

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🧹 Nitpick comments (2)
app/api/auth/me/route.ts (1)

28-35: 🩺 Stability & Availability | 🔵 Trivial

Log ordinary database errors too.

Mongoose errors will not normally be AppError instances, so this condition suppresses diagnostics while still returning a 500. Log or wrap unknown errors before responding.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/api/auth/me/route.ts` around lines 28 - 35, Update the catch block in the
/api/auth/me route to log ordinary database errors as well as AppError instances
before returning the 500 response. Ensure unknown errors are logged or wrapped
with the existing error context, while preserving the current client-facing
response.
components/features/navbar/ScrollController.tsx (1)

14-16: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Reduce effect-driven state churn in scroll bookkeeping.

lastScrollY is only a previous-value cache, but storing it in state and updating it on every scroll causes an additional render/effect pass. Likewise, setPrefersReducedMotion(mediaQuery.matches) synchronously schedules an initialization render. Keep the previous scroll position in a ref and lazily initialize the media-query state.

Proposed refactor
-  const [lastScrollY, setLastScrollY] = useState(0);
+  const lastScrollYRef = useRef(0);
-  const [prefersReducedMotion, setPrefersReducedMotion] = useState(false);
+  const [prefersReducedMotion, setPrefersReducedMotion] = useState(
+    () =>
+      typeof window !== "undefined" &&
+      window.matchMedia("(prefers-reduced-motion: reduce)").matches,
+  );

   useEffect(() => {
     const mediaQuery = window.matchMedia("(prefers-reduced-motion: reduce)");
-    setPrefersReducedMotion(mediaQuery.matches);

     const handler = (e: MediaQueryListEvent) =>
       setPrefersReducedMotion(e.matches);
@@
-    } else if (currentScrollY > lastScrollY && currentScrollY > HIDE_DELAY_PX) {
+    } else if (
+      currentScrollY > lastScrollYRef.current &&
+      currentScrollY > HIDE_DELAY_PX
+    ) {
@@
-      currentScrollY < lastScrollY &&
-      Math.abs(currentScrollY - lastScrollY) > SCROLL_THRESHOLD
+      currentScrollY < lastScrollYRef.current &&
+      Math.abs(currentScrollY - lastScrollYRef.current) > SCROLL_THRESHOLD
@@
-    setLastScrollY(currentScrollY);
+    lastScrollYRef.current = currentScrollY;

Also applies to: 19-26, 30-49

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@components/features/navbar/ScrollController.tsx` around lines 14 - 16, Update
the scroll bookkeeping in the component using lastScrollY to store the previous
position in a ref rather than state, mutating its current value without
triggering renders. Lazily initialize prefersReducedMotion from the media-query
match during useState initialization, and remove the synchronous initialization
update while preserving subsequent media-query change handling.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@__tests__/unit/auth-routes.test.ts`:
- Around line 42-56: Update the test case “connects to the database before
checking for an existing user” to assert invocation order using the mock state:
verify connectDB.mock.invocationCallOrder[0] is less than
findOne.mock.invocationCallOrder[0], while preserving the existing call-count,
arguments, and response assertions.

In `@app/api/auth/me/route.ts`:
- Line 27: Update the `/api/auth/me` handler to return the same explicit user
payload shape used by sign-in and sign-up, mapping the authenticated Mongoose
user’s `_id` to `id` instead of serializing the raw document through
`NextResponse.json({ user })`. Preserve the existing response behavior and
fields expected by `useAuth`.
- Around line 18-21: Call connectDB() at the start of the route’s try block,
before the dashboardUserModel.findById query, so database connectivity is
established before fetching the authenticated user. Reuse the existing connectDB
symbol and preserve the current query and passwordHash projection.

In `@components/features/navbar/AuthButton.tsx`:
- Around line 7-12: Update AuthButton’s authenticated branch to destructure and
invoke the signOut function from useAuth when the control is activated. Replace
the non-interactive div with an accessible, keyboard-focusable control that
includes the user’s username in its label, while preserving the existing
authenticated styling and logout behavior.

In `@proxy.ts`:
- Around line 8-9: Update the public-route matching logic in proxy.ts to use
exact matches or a slash boundary instead of startsWith(route). Ensure
/api/auth/sign-in and /api/auth/sign-up remain public, while similarly prefixed
paths such as -foo or nested endpoints do not bypass authentication; apply the
same change to the additional public-route entries noted in the comment.
- Around line 8-9: Update the proxy authentication allowlist alongside
"/api/auth/sign-in" and "/api/auth/sign-up" to include "/api/auth/sign-out",
allowing sign-out requests without a valid token to reach the sign-out route and
clear stale cookies.

---

Nitpick comments:
In `@app/api/auth/me/route.ts`:
- Around line 28-35: Update the catch block in the /api/auth/me route to log
ordinary database errors as well as AppError instances before returning the 500
response. Ensure unknown errors are logged or wrapped with the existing error
context, while preserving the current client-facing response.

In `@components/features/navbar/ScrollController.tsx`:
- Around line 14-16: Update the scroll bookkeeping in the component using
lastScrollY to store the previous position in a ref rather than state, mutating
its current value without triggering renders. Lazily initialize
prefersReducedMotion from the media-query match during useState initialization,
and remove the synchronous initialization update while preserving subsequent
media-query change handling.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ebb4e92a-dbab-4ecb-b9d8-8a9647923c5a

📥 Commits

Reviewing files that changed from the base of the PR and between 4584ecf and 4fa06a1.

📒 Files selected for processing (18)
  • __tests__/unit/auth-routes.test.ts
  • app/(root)/layout.tsx
  • app/api/auth/me/route.ts
  • app/api/auth/sign-in/route.ts
  • app/api/auth/sign-out/route.ts
  • app/api/auth/sign-up/route.ts
  • app/api/me/route.ts
  • components/Navbar.tsx
  • components/features/navbar/AuthButton.tsx
  • components/features/navbar/Logo.tsx
  • components/features/navbar/NavLinks.tsx
  • components/features/navbar/ScrollController.tsx
  • components/features/navbar/UserSection.tsx
  • components/features/navbar/index.ts
  • components/layout/Navbar.tsx
  • hooks/useAuth.ts
  • lib/auth/jwt.ts
  • proxy.ts
💤 Files with no reviewable changes (2)
  • app/api/me/route.ts
  • components/Navbar.tsx

Comment thread __tests__/unit/auth-routes.test.ts
Comment thread app/api/auth/me/route.ts
Comment thread app/api/auth/me/route.ts Outdated
Comment thread components/features/navbar/AuthButton.tsx
Comment thread proxy.ts
arxja and others added 6 commits July 27, 2026 20:29
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@arxja
arxja merged commit c0f9487 into main Jul 27, 2026
3 checks passed
@arxja
arxja deleted the polish/polish-codebase branch July 27, 2026 17:07
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