✏️ Adjust line breaks in admin login descriptions for improved readability
This commit is contained in:
63
code/websites/pokedex.online/src/router/guards.js
Normal file
63
code/websites/pokedex.online/src/router/guards.js
Normal 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 || '/';
|
||||
}
|
||||
@@ -59,24 +59,24 @@
|
||||
<div class="info-card">
|
||||
<h3>🔐 Protected Access</h3>
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="info-card">
|
||||
<h3>🔒 Security</h3>
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="info-card">
|
||||
<h3>📱 Device Specific</h3>
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user