import { useCookie } from "nuxt/app";
import { useAuthenticationStore } from "../stores/Authentication/authentication";
export default defineNuxtRouteMiddleware(async (to, from) => {
let layout = to.meta.layout;
let isAuthLayout = layout == 'dashboard' || layout == 'messenger';
// In case the layout not dashboard then this not in consirn
if (!isAuthLayout) return true;
// Check if this is the dashboard but the user doesnt have token
if (!useCookie('__Secure_TK').value) return 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,$error.status)
// return navigateTo('/register');
}
})
import { useCookie } from "nuxt/app";
import { useAuthenticationStore } from "../stores/Authentication/authentication";
export default defineNuxtRouteMiddleware(async (to, from) => {
let layout = to.meta.layout;
let isAuthLayout = layout == 'dashboard' || layout == 'messenger';
// In case the layout not dashboard then this not in consirn
if (!isAuthLayout) return true;
// Check if this is the dashboard but the user doesnt have token
if (!useCookie('__Secure_TK').value) return 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,$error.status)
// return navigateTo('/register');
}
})