import { useCookie } from "nuxt/app";
import { useAuthenticationStore } from "../stores/Authentication/authentication";
import { useRouter } from "vue-router";
export default defineNuxtRouteMiddleware(async (to, from) => {
let layout = to.meta.layout;
const route = useRouter()
// In case the layout not dashboard then this not in consirn
if (layout != 'dashboard') return true;
// Check if this is the dashboard but the user doesnt have token
if (layout == 'dashboard' && !useCookie('__Secure_TK').value?.length) navigateTo('/register');
// Get user data from the token
let authenticationStore = useAuthenticationStore();
try {
let {data} = await authenticationStore.me();
if (data.is_active) authenticationStore.signInUser(data)
else return navigateTo('/register');
} catch ($error) {
console.log($error);
// return navigateTo('/register') -> problem line
}
})
import { useCookie } from "nuxt/app";
import { useAuthenticationStore } from "../stores/Authentication/authentication";
import { useRouter } from "vue-router";
export default defineNuxtRouteMiddleware(async (to, from) => {
let layout = to.meta.layout;
const route = useRouter()
// In case the layout not dashboard then this not in consirn
if (layout != 'dashboard') return true;
// Check if this is the dashboard but the user doesnt have token
if (layout == 'dashboard' && !useCookie('__Secure_TK').value?.length) navigateTo('/register');
// Get user data from the token
let authenticationStore = useAuthenticationStore();
try {
let {data} = await authenticationStore.me();
if (data.is_active) authenticationStore.signInUser(data)
else return navigateTo('/register');
} catch ($error) {
console.log($error);
// return navigateTo('/register') -> problem line
}
})