export default defineNuxtRouteMiddleware(async (to, from) => { // If accessing root path, check authentication and redirect appropriately if (to.path === '/') { if (process.client) { try { // Check if user is authenticated const { data: validateUser } = await useFetch("/api/auth/validate", { method: "GET", server: false }); // If authenticated, go to dashboard, otherwise login if (validateUser.value && validateUser.value.statusCode === 200) { return navigateTo("/dashboard"); } else { return navigateTo("/login"); } } catch (error) { // If validation fails, redirect to login return navigateTo("/login"); } } // Server-side fallback return navigateTo("/login"); } });