Restrict page access using environment variables. Set NEXT_PUBLIC_DISABLED_ROUTES with the pages to disable (e.g., ["Home"]). If a user tries to access a disabled page, redirect them to the micro frontend specified in NEXT_PUBLIC_MFE_REDIRECT_URL. - #99
Conversation
… has been implemented, along with a redirect URL that redirects users to another MFE (microfrontend). For example, if ["HOME"] is assigned to the restricted pages environment variable, users will not be able to access the Home page within the application. The redirect URL, such as /mfe, can be configured to redirect users to the corresponding MFE whenever they try to access a restricted page.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThe change adds typed route constants and environment parsing for disabled routes, applies disabled-route redirects in middleware, and conditionally hides the Home and Profile UI entries after client mounting. ChangesRoute disabling
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Browser
participant middleware
participant env
participant HomePage
participant Footer
Browser->>middleware: Request route
middleware->>env: Read disabled-route configuration
env-->>middleware: Normalized disabled route keys
middleware-->>Browser: Login redirect, MFE redirect, or /404 rewrite
HomePage->>env: Check PROFILE
env-->>HomePage: Profile route status
Footer->>env: Check HOME
env-->>Footer: Home route status
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 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 |
|
@coderabbitai please review my pr |
|
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
.env.example (1)
8-10: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove the space before the equal sign.
Environment variable parsers can sometimes misinterpret spaces around the equal sign (e.g., treating the key as
NEXT_PUBLIC_CONTENT). Removing the space aligns with standard.envformatting conventions.🧹 Proposed fix
-NEXT_PUBLIC_CONTENT = +NEXT_PUBLIC_CONTENT= NEXT_PUBLIC_DISABLED_ROUTES= NEXT_PUBLIC_MFE_REDIRECT_URL=🤖 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 @.env.example around lines 8 - 10, Remove the space before the equals sign in the NEXT_PUBLIC_CONTENT environment variable declaration, matching the formatting of NEXT_PUBLIC_DISABLED_ROUTES and NEXT_PUBLIC_MFE_REDIRECT_URL.Source: Linters/SAST tools
libs/shared-lib/src/utils/env.ts (1)
36-51: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winMemoize the disabled route keys to improve performance.
Since
isRouteDisabledis called during React component renders (such as inFooterandpage.tsx), the environment variable is currently re-parsed (which may involveJSON.parseand array iterations) on every single render. You can optimize this by caching the parsed result at the module level, as environment variables do not change during runtime.Additionally, consider adding
.filter(Boolean)to prevent empty strings from being included if the configuration contains trailing commas (e.g.,HOME,).♻️ Proposed refactor
+let cachedDisabledKeys: string[] | null = null; + export const getDisabledRouteKeys = (): string[] => { + if (cachedDisabledKeys) return cachedDisabledKeys; const raw = (getEnvValue('NEXT_PUBLIC_DISABLED_ROUTES') ?? '').trim(); - if (!raw) return []; + if (!raw) { + cachedDisabledKeys = []; + return cachedDisabledKeys; + } let keys: string[] = []; if (raw.startsWith('[')) { try { const parsed = JSON.parse(raw); keys = Array.isArray(parsed) ? parsed.map(String) : []; } catch { keys = []; } } else { keys = raw.split(','); } - return keys.map((key) => key.trim().toUpperCase()); + cachedDisabledKeys = keys.map((key) => key.trim().toUpperCase()).filter(Boolean); + return cachedDisabledKeys; };🤖 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 `@libs/shared-lib/src/utils/env.ts` around lines 36 - 51, Memoize the result of getDisabledRouteKeys at module scope so the environment value is parsed only once during runtime, while preserving its existing JSON and comma-separated formats. Update the normalization step to filter out empty keys, including those produced by trailing commas, before returning the uppercased route keys.
🤖 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 `@apps/shikshagraha-app/src/middleware.ts`:
- Around line 56-59: Update the disabled-route handling in the middleware so the
unauthenticated redirect guarded by !accToken only runs when pathname is not
ROUTES.LOGIN. Preserve the existing fall-through behavior for the disabled login
route, including its MFE redirect or 404 rewrite.
---
Nitpick comments:
In @.env.example:
- Around line 8-10: Remove the space before the equals sign in the
NEXT_PUBLIC_CONTENT environment variable declaration, matching the formatting of
NEXT_PUBLIC_DISABLED_ROUTES and NEXT_PUBLIC_MFE_REDIRECT_URL.
In `@libs/shared-lib/src/utils/env.ts`:
- Around line 36-51: Memoize the result of getDisabledRouteKeys at module scope
so the environment value is parsed only once during runtime, while preserving
its existing JSON and comma-separated formats. Update the normalization step to
filter out empty keys, including those produced by trailing commas, before
returning the uppercased route keys.
🪄 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: ec6652ec-8792-49b0-905b-3a5530c7da78
📒 Files selected for processing (6)
.env.exampleapps/shikshagraha-app/src/app/home/page.tsxapps/shikshagraha-app/src/constants/routes.tsapps/shikshagraha-app/src/middleware.tslibs/shared-lib/src/lib/Footer/Footer.tsxlibs/shared-lib/src/utils/env.ts
|
@coderabbitai review |
✅ Action performedReview finished.
|
Summary by CodeRabbit
New Features
Bug Fixes