✏️ Adjust line breaks in admin login descriptions for improved readability

This commit is contained in:
2026-01-28 22:46:49 +00:00
parent 07a6f902d9
commit 56578917e8
2 changed files with 69 additions and 6 deletions

View File

@@ -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 || '/';
}