From 56578917e8a208264b64654c1b7950c5676fb501 Mon Sep 17 00:00:00 2001 From: FragginWagon Date: Wed, 28 Jan 2026 22:46:49 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20Adjust=20line=20breaks=20i?= =?UTF-8?q?n=20admin=20login=20descriptions=20for=20improved=20readability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pokedex.online/src/router/guards.js | 63 +++++++++++++++++++ .../pokedex.online/src/views/AdminLogin.vue | 12 ++-- 2 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 code/websites/pokedex.online/src/router/guards.js diff --git a/code/websites/pokedex.online/src/router/guards.js b/code/websites/pokedex.online/src/router/guards.js new file mode 100644 index 0000000..88435d1 --- /dev/null +++ b/code/websites/pokedex.online/src/router/guards.js @@ -0,0 +1,63 @@ +/** + * Route Guards + * + * Navigation guards for protecting admin routes + */ + +import { useAuth } from '../composables/useAuth.js'; + +/** + * Create router guards with auth check + * @param {Router} router - Vue Router instance + */ +export function setupAuthGuards(router) { + router.beforeEach(async (to, from, next) => { + const { isAuthenticated, initializeAuth } = useAuth(); + + // Initialize auth from stored token + if (!isAuthenticated.value) { + await initializeAuth(); + } + + // Check if route requires admin access + if (to.meta.requiresAdmin) { + if (!isAuthenticated.value) { + // Redirect to login + next({ + name: 'admin-login', + query: { redirect: to.fullPath } + }); + } else { + next(); + } + } else { + next(); + } + }); + + router.afterEach((to, from) => { + // Optional: Log navigation for debugging + if (to.meta.requiresAdmin) { + console.log(`[Auth] Navigated to protected route: ${to.path}`); + } + }); +} + +/** + * Check if a route requires authentication + * @param {RouteLocationNormalized} route - Route object + * @returns {boolean} True if route requires authentication + */ +export function requiresAuthentication(route) { + return route.meta.requiresAdmin === true; +} + +/** + * Get redirect path after login + * @param {Router} router - Vue Router instance + * @returns {string} Path to redirect to + */ +export function getPostLoginRedirect(router) { + const redirect = router.currentRoute.value.query.redirect; + return redirect || '/'; +} diff --git a/code/websites/pokedex.online/src/views/AdminLogin.vue b/code/websites/pokedex.online/src/views/AdminLogin.vue index a0e7918..62358de 100644 --- a/code/websites/pokedex.online/src/views/AdminLogin.vue +++ b/code/websites/pokedex.online/src/views/AdminLogin.vue @@ -59,24 +59,24 @@

🔐 Protected Access

- Admin login provides access to protected features like the Gamemaster Manager - and other administration tools. + Admin login provides access to protected features like the + Gamemaster Manager and other administration tools.

🔒 Security

- Your session is protected with JWT authentication. Tokens expire after 7 days - of inactivity. + Your session is protected with JWT authentication. Tokens expire + after 7 days of inactivity.

📱 Device Specific

- Your login is stored securely in your browser's local storage. Each device - requires its own login. + Your login is stored securely in your browser's local storage. Each + device requires its own login.