Skip to content

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

Open
farhanp1502 wants to merge 5 commits into
ELEVATE-Project:release-1.3.0from
farhanp1502:release-1.3.0

Conversation

@farhanp1502

@farhanp1502 farhanp1502 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Added configurable controls to hide selected pages via environment settings.
    • When a disabled page is accessed, the app now redirects to a login flow or an external destination (when configured).
    • Centralized route definitions improve consistency across navigation and redirects.
  • Bug Fixes

    • Improved handling for disabled routes, including correct behavior for authenticated vs. unauthenticated users.
    • Updated Home/Profile and footer navigation display to avoid showing restricted items during initial render.

… 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.
@farhanp1502 farhanp1502 changed the title Restricting the pages through env for different env. Restricting the pages through env for different env. Jul 17, 2026
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b1bcffa5-7298-46d5-baf4-72d28fcbd3fd

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The 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.

Changes

Route disabling

Layer / File(s) Summary
Route contract and environment parsing
apps/shikshagraha-app/src/constants/routes.ts, libs/shared-lib/src/utils/env.ts, .env.example
Adds typed route constants and parses NEXT_PUBLIC_DISABLED_ROUTES and NEXT_PUBLIC_MFE_REDIRECT_URL from environment configuration.
Middleware route enforcement
apps/shikshagraha-app/src/middleware.ts
Matches disabled request paths and redirects unauthenticated requests to login, while redirecting authenticated requests to the configured MFE URL or rewriting them to /404.
Conditional navigation and profile visibility
apps/shikshagraha-app/src/app/home/page.tsx, libs/shared-lib/src/lib/Footer/Footer.tsx
Hides the profile icon and Home bottom-navigation action when their routes are disabled, after components mount.

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
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: environment-based route restriction and redirect behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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

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.

@farhanp1502 farhanp1502 changed the title Restricting the pages through env for different env. 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. Jul 17, 2026
@farhanp1502

Copy link
Copy Markdown
Contributor Author

@coderabbitai please review my pr

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

@farhanp1502 I’ll review PR #99, focusing on disabled-route matching, environment-variable handling, and redirect behavior.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
.env.example (1)

8-10: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove 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 .env formatting 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 win

Memoize the disabled route keys to improve performance.

Since isRouteDisabled is called during React component renders (such as in Footer and page.tsx), the environment variable is currently re-parsed (which may involve JSON.parse and 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

📥 Commits

Reviewing files that changed from the base of the PR and between 52d8d9d and e8e94b2.

📒 Files selected for processing (6)
  • .env.example
  • apps/shikshagraha-app/src/app/home/page.tsx
  • apps/shikshagraha-app/src/constants/routes.ts
  • apps/shikshagraha-app/src/middleware.ts
  • libs/shared-lib/src/lib/Footer/Footer.tsx
  • libs/shared-lib/src/utils/env.ts

Comment thread apps/shikshagraha-app/src/middleware.ts
@Vinod-V3

Copy link
Copy Markdown
Collaborator

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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.

2 participants