Add redirect from protected pages to login
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user