Add redirect from protected pages to login

This commit is contained in:
2025-08-11 18:44:42 +02:00
parent 129da829e7
commit bb08a62e5d

View File

@@ -1,12 +1,16 @@
import { fa } from "vuetify/locale";
// file: ~/middleware/authentication.global.ts
export default defineNuxtRouteMiddleware(async (to, next) => {
export default defineNuxtRouteMiddleware(async (to, from, next) => {
const { status } = useAuth();
const auth = status.value === "authenticated" ? true : false;
const isProtected = (await to.meta.auth) === true ? true : false;
if (!auth && isProtected) {
// User is not authenticated and page is protected
if (from.meta.auth) {
//viene de una pagina protegida
return navigateTo("/login");
} //viene de una pagina no protegida
return abortNavigation();
} else if (auth && !isProtected) {
// User is authenticated and page is not protected