Skip to content

feat(middleware): add page-level feature flag protection via definePageMeta#77

Merged
nicokempe merged 5 commits into
mainfrom
feat/new-page-protection
Aug 22, 2025
Merged

feat(middleware): add page-level feature flag protection via definePageMeta#77
nicokempe merged 5 commits into
mainfrom
feat/new-page-protection

Conversation

@nicokempe
Copy link
Copy Markdown
Owner

✅ PR Checklist

Please ensure the following before submitting your PR:

  • My commit message follows Conventional Commits
  • I’ve tested the changes and confirmed they work as expected
  • I’ve updated any relevant documentation
  • I’ve added tests (if applicable)

🔗 Linked Issue

No issue created.

📖 Description

This PR introduces page-level feature flag protection via Nuxt middleware, enabling developers to guard entire pages with definePageMeta.

Key changes:

  • ✨ Middleware:
    Added global route middleware (src/runtime/middleware/featureFlag.ts) that restricts access to routes based on feature flags.
    • Supports featureFlag for required feature
    • Optional featureFallback for redirects when disabled
    • Optional featureNotifyOnBlock for logging blocked access
  • 📝 Documentation:
    Updated README.md with usage examples for definePageMeta to demonstrate page-level protection.
  • 🏗️ Types: Introduced a new PageMeta interface (types/feature-flags.d.ts) to extend Nuxt schema with featureFlag, featureFallback, and featureNotifyOnBlock.
  • 🧪 Tests:
    Added unit tests (test/unit/featureFlagMiddleware.test.ts) covering:
    • Redirect to fallback when feature is disabled
    • Error handling when disabled without fallback
    • Normal behavior when feature is enabled
  • 🎮 Playground Example: Added a new demo page (playground/pages/new-protected.vue) showing feature-flag-based route protection in action.

This feature makes it easier to manage feature-gated access at the routing level, ensuring consistent user access control across the app.

🚨 Breaking Changes

  • Yes
  • No

🧪 Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 🧹 Code style / formatting
  • 🔨 Refactoring (no functional changes)
  • 🧰 Tooling / CI
  • 📝 Docs update
  • 🧪 Tests
  • 💡 Other (please describe):

🧩 Additional Context

Thank you for contributing! 💚

Signed-off-by: Nico Kempe <git@nicokempe.de>
…ration

Signed-off-by: Nico Kempe <git@nicokempe.de>
…gh definePageMeta

Signed-off-by: Nico Kempe <git@nicokempe.de>
Signed-off-by: Nico Kempe <git@nicokempe.de>
Signed-off-by: Nico Kempe <git@nicokempe.de>
@nicokempe nicokempe self-assigned this Aug 22, 2025
@nicokempe nicokempe added the ✨ enhancement new feature or enhancement label Aug 22, 2025
@nicokempe nicokempe changed the title feat: add new page protection feat(middleware): add page-level feature flag protection via definePageMeta Aug 22, 2025
@nicokempe nicokempe merged commit bc32e5e into main Aug 22, 2025
7 checks passed
@nicokempe nicokempe deleted the feat/new-page-protection branch August 22, 2025 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✨ enhancement new feature or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant