Added Dashboard Pages#69
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughThis PR restructures the admin dashboard architecture by consolidating authentication flows, migrating token storage to localStorage, and reorganizing routes. It documents 12 identified bugs and implements fixes across auth guards, login redirects, token handling, axios interceptors, and provider scoping. ChangesAuth Refactoring and Admin Dashboard Reorganization
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ 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
🤖 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 `@bugs.md`:
- Around line 117-131: The fenced code block containing the folder tree is
missing a language identifier which triggers markdown lint MD040; update the
code fence by adding a language tag (e.g., "text") after the opening triple
backticks so the block becomes ```text ... ```, ensuring the folder-tree snippet
(the block containing app/, admin/, (auth)/, layout.tsx, page.tsx, etc.) is
correctly fenced.
🪄 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: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: d119a79b-298a-4039-a730-55913a1ec48c
📒 Files selected for processing (5)
bugs.mdnext-ts/app/(dashboard)/admin/(protected)/applications/page.tsxnext-ts/app/(dashboard)/admin/(protected)/courses/page.tsxnext-ts/app/(dashboard)/admin/(protected)/settings/page.tsxnext-ts/app/(dashboard)/admin/(protected)/students/page.tsx
There was a problem hiding this comment.
Actionable comments posted: 4
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
next-ts/src/components/AuthGuard/index.tsx (1)
12-22:⚠️ Potential issue | 🟠 Major | ⚡ Quick winPath-based student routes now fall back to the admin login.
axiosInstancein this PR treats/studentand/withdrawas student auth entry points, and the stack context showsapp/(student)/layout.tsxnow usesAuthGuard. Lines 12-22 only inspect the host, so protected student pages served from the main host will redirect to/admin. Mirror the pathname fallback here or share the same helper to keep both flows aligned.Suggested fix
const getDefaultRedirectPath = () => { if (globalThis.window === undefined) { return "/admin"; } - const host = globalThis.window.location.host.toLowerCase(); - if (host.startsWith("student.")) { + const { host, pathname } = globalThis.window.location; + const normalizedHost = host.toLowerCase(); + + if (normalizedHost.startsWith("student.")) { + return "/student"; + } + + if (/^\/(student|withdraw)(\/|$)/.test(pathname)) { return "/student"; } return "/admin"; };🤖 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 `@next-ts/src/components/AuthGuard/index.tsx` around lines 12 - 22, getDefaultRedirectPath currently only inspects window.location.host and will misroute student-protected pages served on the main host; update getDefaultRedirectPath to also inspect globalThis.window.location.pathname (e.g., check if pathname startsWith("/student") or "/withdraw") and return "/student" when matched, or refactor to call the same shared helper used by axiosInstance/app/(student)/layout.tsx so both host- and path-based detection yield the same "/student" vs "/admin" redirect.
🤖 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 `@next-ts/app/`(admin)/admin/page.tsx:
- Around line 15-21: Auth state is restored asynchronously in AuthProvider so
the page currently renders the login form before auth finishes; update
AuthProvider to expose a bootstrap/hydration flag (eg. isAuthBootstrapped or
isHydrated) from useAuthState, then in this component wait for that flag before
rendering or running the redirect: use the existing useAuthState values
(currentUser, isPending, isError) plus the new isAuthBootstrapped flag in the
useEffect and in the component render path to return null or a loader until
isAuthBootstrapped is true; ensure the redirect
(router.replace('/admin/dashboard')) only runs after isAuthBootstrapped and
currentUser are truthy so already-signed-in users never see the form (also apply
the same check where the form is rendered around line 31).
In `@next-ts/app/`(student)/layout.tsx:
- Line 1: The student layout imports AuthGuard but doesn't enforce it; wrap the
layout's rendered children with the AuthGuard component so all pages under this
layout are protected. Locate the exported layout component in layout.tsx (the
function that receives children) and return JSX that nests the existing layout
tree inside <AuthGuard>...</AuthGuard> (preserving any existing providers or
markup order), ensuring children remain passed through to AuthGuard. Make the
change for the layout component that currently renders the student area so route
protection is applied.
In `@next-ts/src/lib/utils/axiosInstance.ts`:
- Around line 53-68: The handler currently calls sessionStorage.clear(), which
wipes all origin-scoped session data; replace that call in the 401 error branch
(the block referencing hadToken, redirectPath, currentPath,
getUnauthorizedRedirectPath(), localStorage.removeItem("token")) with targeted
removal of only auth-owned session keys: either iterate an explicit allowlist
constant (e.g., AUTH_SESSION_KEYS) and call sessionStorage.removeItem for each,
or remove keys by a known prefix (e.g., keys startingWith "auth:" or
"session_auth_")—update the code where sessionStorage.clear() appears to use
this targeted cleanup before calling globalThis.location.replace(redirectPath).
In `@next-ts/src/providers/auth-provider/index.tsx`:
- Around line 27-30: The code is clearing the entire origin's localStorage on
token expiry (localStorage.clear()), which wipes unrelated data; replace that
with removing only auth-related keys: keep localStorage.removeItem("token") and
remove specific keys used by the auth flow (e.g. "refreshToken", "auth:user",
"auth:roles" or whatever keys your auth code uses), or iterate over keys and
remove only those with the auth prefix (e.g. startsWith("auth:")), instead of
calling localStorage.clear(); update the block around the exp check where
localStorage.clear() is called to target only auth-owned keys.
---
Outside diff comments:
In `@next-ts/src/components/AuthGuard/index.tsx`:
- Around line 12-22: getDefaultRedirectPath currently only inspects
window.location.host and will misroute student-protected pages served on the
main host; update getDefaultRedirectPath to also inspect
globalThis.window.location.pathname (e.g., check if pathname
startsWith("/student") or "/withdraw") and return "/student" when matched, or
refactor to call the same shared helper used by
axiosInstance/app/(student)/layout.tsx so both host- and path-based detection
yield the same "/student" vs "/admin" redirect.
🪄 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: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: aef98d5b-a9cb-424e-9d6d-b0330e65c0b8
📒 Files selected for processing (19)
bugs.mdnext-ts/app/(admin)/admin/(workspace)/applications/page.tsxnext-ts/app/(admin)/admin/(workspace)/courses/page.tsxnext-ts/app/(admin)/admin/(workspace)/dashboard/page.tsxnext-ts/app/(admin)/admin/(workspace)/dashboard/style.tsnext-ts/app/(admin)/admin/(workspace)/layout.tsxnext-ts/app/(admin)/admin/(workspace)/settings/page.tsxnext-ts/app/(admin)/admin/(workspace)/students/page.tsxnext-ts/app/(admin)/admin/layout.tsxnext-ts/app/(admin)/admin/page.tsxnext-ts/app/(admin)/admin/style.tsnext-ts/app/(dashboard)/admin/(protected)/layout.tsxnext-ts/app/(dashboard)/admin/layout.tsxnext-ts/app/(public)/layout.tsxnext-ts/app/(student)/layout.tsxnext-ts/app/layout.tsxnext-ts/src/components/AuthGuard/index.tsxnext-ts/src/lib/utils/axiosInstance.tsnext-ts/src/providers/auth-provider/index.tsx
💤 Files with no reviewable changes (6)
- next-ts/app/(admin)/admin/(workspace)/courses/page.tsx
- next-ts/app/(admin)/admin/(workspace)/students/page.tsx
- next-ts/app/(admin)/admin/(workspace)/applications/page.tsx
- next-ts/app/(admin)/admin/(workspace)/settings/page.tsx
- next-ts/app/(dashboard)/admin/layout.tsx
- next-ts/app/(dashboard)/admin/(protected)/layout.tsx
✅ Files skipped from review due to trivial changes (5)
- next-ts/app/(admin)/admin/layout.tsx
- next-ts/app/(public)/layout.tsx
- next-ts/app/(admin)/admin/(workspace)/layout.tsx
- next-ts/app/layout.tsx
- bugs.md
|
@CodeRabbit resolve |
✅ Action performedComments resolved. Approval is disabled; enable |
mblebelo
left a comment
There was a problem hiding this comment.
All checks passed and conversations resolved ✅
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes