fix router error#6
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThe PR prepares the client for Vercel deployment by adding a SPA rewrite rule, production API URL, and Vercel Analytics. The admin controller is extended to compute per-role user counts via a Prisma ChangesVercel Deployment & Production API Wiring
Admin Role-Based Stats (Server + Client)
Debug Cleanup, Form Fix, and Breadcrumb Refactor
Sequence Diagram(s)sequenceDiagram
participant Browser
participant AdminController
participant Prisma
Browser->>AdminController: GET /admin/stats
AdminController->>Prisma: $transaction([count users, count subs, groupBy role, ...])
Prisma-->>AdminController: [totalUser, totalSubs, totalRoleUser[{role, _count}], ...]
AdminController->>AdminController: build roleCounts {ADMIN, USER} from totalRoleUser
AdminController-->>Browser: stats { users: { total, totalUserByRoles }, ... }
Browser->>Browser: render metricCards with ADMIN/USER counts + colored dots
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
client/src/components/dashboard/AddForm.jsx (1)
58-61: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick winRemove submit-time debug logging in production path.
Line 59 logs validated form payloads during submit. This reintroduces debug noise and can expose user-entered values in browser logs.
Suggested fix
const onSubmit = (values) => { - console.log("Validated Data ready for TanStack Mutation:", values); - // mutation.mutate(values) goes here - mutation.mutate(values) + mutation.mutate(values); };🤖 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 `@client/src/components/dashboard/AddForm.jsx` around lines 58 - 61, Remove the console.log statement from the onSubmit function that logs the validated form values. This debug logging in the production submission path should be eliminated as it can expose user-entered data in browser logs and adds unnecessary noise. Keep only the mutation.mutate(values) call inside the onSubmit function.
🧹 Nitpick comments (2)
client/src/lib/utils.js (1)
10-10: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winFail fast when
VITE_API_URLis missing (Line 10).Returning the env value directly can propagate invalid URLs (
undefined/api/...) into auth calls. Add a guard here so misconfiguration is detected immediately.Proposed fix
export function getApiBaseUrl() { - return import.meta.env.VITE_API_URL; + const baseUrl = import.meta.env.VITE_API_URL; + if (!baseUrl) { + throw new Error("Missing VITE_API_URL"); + } + return baseUrl.replace(/\/$/, ""); }🤖 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 `@client/src/lib/utils.js` at line 10, The function is returning import.meta.env.VITE_API_URL without validating that it exists, which allows undefined values to propagate into auth calls and create invalid URLs. Add a guard check before the return statement to ensure VITE_API_URL is defined and not empty, and throw an error or log a clear error message if the environment variable is missing. This way, misconfiguration will be caught immediately rather than causing issues downstream.client/.env (1)
1-1: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAvoid using production API as the default in shared
.env(Line 1).This makes local/dev traffic hit production unless every developer overrides it. Prefer local default in
.envand keep production in.env.production(or Vercel project env vars).Suggested env split
# client/.env - VITE_API_URL=https://subly-backend-iuej.onrender.com + VITE_API_URL=http://localhost:3000# client/.env.production VITE_API_URL=https://subly-backend-iuej.onrender.com🤖 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 `@client/.env` at line 1, The shared .env file contains the production API URL for VITE_API_URL, which forces all developers to hit production by default unless they manually override it. Move the production URL (https://subly-backend-iuej.onrender.com) to a new .env.production file and replace the VITE_API_URL in the shared .env file with a local development default (such as http://localhost:3000 or your local dev API endpoint). This ensures developers use local/dev endpoints by default while production builds automatically use the correct production URL.
🤖 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 `@client/src/pages/dashboard/Admin.jsx`:
- Around line 44-48: The getValue accessor in the role-count stat cards is using
an incorrect path to access the stats data. Currently it reads from
stats?.totalUserByRoles?.ADMIN, but the API payload provides this data nested
under stats.users.totalUserByRoles instead. Update the getValue function for the
admin role card (key: "admin") and all other role-count cards to access the data
through the correct nested path by changing stats?.totalUserByRoles to
stats?.users?.totalUserByRoles to properly retrieve the role counts from the API
response.
---
Outside diff comments:
In `@client/src/components/dashboard/AddForm.jsx`:
- Around line 58-61: Remove the console.log statement from the onSubmit function
that logs the validated form values. This debug logging in the production
submission path should be eliminated as it can expose user-entered data in
browser logs and adds unnecessary noise. Keep only the mutation.mutate(values)
call inside the onSubmit function.
---
Nitpick comments:
In `@client/.env`:
- Line 1: The shared .env file contains the production API URL for VITE_API_URL,
which forces all developers to hit production by default unless they manually
override it. Move the production URL (https://subly-backend-iuej.onrender.com)
to a new .env.production file and replace the VITE_API_URL in the shared .env
file with a local development default (such as http://localhost:3000 or your
local dev API endpoint). This ensures developers use local/dev endpoints by
default while production builds automatically use the correct production URL.
In `@client/src/lib/utils.js`:
- Line 10: The function is returning import.meta.env.VITE_API_URL without
validating that it exists, which allows undefined values to propagate into auth
calls and create invalid URLs. Add a guard check before the return statement to
ensure VITE_API_URL is defined and not empty, and throw an error or log a clear
error message if the environment variable is missing. This way, misconfiguration
will be caught immediately rather than causing issues downstream.
🪄 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
Run ID: 946d4454-5aca-40f3-9e00-0bd54182ce09
⛔ Files ignored due to path filters (1)
client/package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (13)
client/.envclient/package.jsonclient/src/components/Breadcrumb.jsxclient/src/components/dashboard/AddForm.jsxclient/src/components/dashboard/Overview.jsxclient/src/components/dashboard/Stats.jsxclient/src/lib/utils.jsclient/src/main.jsxclient/src/pages/dashboard/Admin.jsxclient/src/pages/dashboard/Overview.jsxclient/src/pages/dashboard/Subscriptions.jsxclient/vercel.jsonserver/src/controllers/admin.controller.js
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
Chores