From fcfc4215e044c7125f25bbcddf947d40c32c1acf Mon Sep 17 00:00:00 2001 From: FragginWagon Date: Thu, 29 Jan 2026 02:06:58 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A6=20Add=20feature=20flag=20checks=20?= =?UTF-8?q?to=20route=20guards=20and=20logging=20for=20flagged=20routes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pokedex.online/src/router/guards.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/code/websites/pokedex.online/src/router/guards.js b/code/websites/pokedex.online/src/router/guards.js index 88435d1..f8f907e 100644 --- a/code/websites/pokedex.online/src/router/guards.js +++ b/code/websites/pokedex.online/src/router/guards.js @@ -1,24 +1,36 @@ /** * Route Guards * - * Navigation guards for protecting admin routes + * Navigation guards for protecting admin routes and feature-flagged routes */ import { useAuth } from '../composables/useAuth.js'; +import { useFeatureFlags } from '../composables/useFeatureFlags.js'; /** - * Create router guards with auth check + * Create router guards with auth and feature flag checks * @param {Router} router - Vue Router instance */ export function setupAuthGuards(router) { router.beforeEach(async (to, from, next) => { const { isAuthenticated, initializeAuth } = useAuth(); + const { isEnabled } = useFeatureFlags(); // Initialize auth from stored token if (!isAuthenticated.value) { await initializeAuth(); } + // Check if route is behind a feature flag + if (to.meta.featureFlag) { + const flagEnabled = isEnabled.value(to.meta.featureFlag); + if (!flagEnabled) { + console.warn(`[Router] Feature flag "${to.meta.featureFlag}" is disabled`); + next({ name: 'Home', replace: true }); + return; + } + } + // Check if route requires admin access if (to.meta.requiresAdmin) { if (!isAuthenticated.value) { @@ -40,6 +52,9 @@ export function setupAuthGuards(router) { if (to.meta.requiresAdmin) { console.log(`[Auth] Navigated to protected route: ${to.path}`); } + if (to.meta.featureFlag) { + console.log(`[FeatureFlag] Navigated to flagged route: ${to.path} (flag: ${to.meta.featureFlag})`); + } }); }