kiri
kiri
NNuxt
Created by kiri on 9/13/2024 in #❓・help
500[nuxt] instance unavailable Hello so I am having middlewae with following code
export default defineNuxtRouteMiddleware((to, from) => {
const authStore = useAuthStore();

console.log(`Navigating from ${from.path} to ${to.path}`);

const publicPaths = ['/'];

if (publicPaths.includes(to.path)) {
console.log('Public path, no redirection needed');
return;
}

if (!authStore.isAuthenticated) {
if (to.path !== LOCAL_ENDPOINTS.login) {
console.log('User is not authenticated, redirecting to login');
return navigateTo(LOCAL_ENDPOINTS.login);
}
}
else if (to.path === LOCAL_ENDPOINTS.login) {
console.log('User is authenticated, redirecting to dashboard');
return navigateTo(LOCAL_ENDPOINTS.dashboard);
}

return;
});
export default defineNuxtRouteMiddleware((to, from) => {
const authStore = useAuthStore();

console.log(`Navigating from ${from.path} to ${to.path}`);

const publicPaths = ['/'];

if (publicPaths.includes(to.path)) {
console.log('Public path, no redirection needed');
return;
}

if (!authStore.isAuthenticated) {
if (to.path !== LOCAL_ENDPOINTS.login) {
console.log('User is not authenticated, redirecting to login');
return navigateTo(LOCAL_ENDPOINTS.login);
}
}
else if (to.path === LOCAL_ENDPOINTS.login) {
console.log('User is authenticated, redirecting to dashboard');
return navigateTo(LOCAL_ENDPOINTS.dashboard);
}

return;
});
and also a store with the followind
export const useAuthStore = defineStore('auth', () => {
const isAuthenticated = ref(false);
const accessToken = ref<string | null>(null);
const isLoggedIn = computed(() => isAuthenticated.value);
const login = (token: string) => {
isAuthenticated.value = true;
accessToken.value = token;
};

const logout = () => {
isAuthenticated.value = false;
accessToken.value = null;
};

const setToken = (token: string) => {
accessToken.value = token;
};

return {
isAuthenticated,
accessToken,
isLoggedIn,
login,
logout,
setToken,
};
}, {
persist: true,
});
export const useAuthStore = defineStore('auth', () => {
const isAuthenticated = ref(false);
const accessToken = ref<string | null>(null);
const isLoggedIn = computed(() => isAuthenticated.value);
const login = (token: string) => {
isAuthenticated.value = true;
accessToken.value = token;
};

const logout = () => {
isAuthenticated.value = false;
accessToken.value = null;
};

const setToken = (token: string) => {
accessToken.value = token;
};

return {
isAuthenticated,
accessToken,
isLoggedIn,
login,
logout,
setToken,
};
}, {
persist: true,
});
but I am getting the following error >> 500 [nuxt] A composable that requires access to the Nuxt instance was called outside of a plugin, Nuxt hook, Nuxt middleware, or Vue setup function. This is probably not a Nuxt bug. Find out more at https://nuxt.com/docs/guide/concepts/auto-imports#vue-and-nuxt-composables.
2 replies
NNuxt
Created by kiri on 8/22/2024 in #❓・help
Did you mean to import "ignore/index.js"? ELIFECYCLE  Command failed with exit code 1
Hello I am encountering this error while running pnpm install ,what should be done ?? ERROR Cannot find package 'E:\lifeline\nexeor\Training-Arc\frontedn\NUXT3-Initiation-Arc-Online-Voting-Platform\poll-frontend\nodemodules.pnpm\[email protected]@[email protected]_@[email protected][email protected][email protected][email protected]_rh2msb2zlxrluwiknwdn23245q\node_modules\ignore\package.json' imported from E:\lifeline\nexeor\Training-Arc\frontedn\NUXT3-Initiation-Arc-Online-Voting-Platform\poll-frontend\nodemodules.pnpm\[email protected]@[email protected]_@[email protected][email protected][email protected][email protected]_rh2msb2zlxrluwiknwdn23245q\node_modules\nuxt\dist\index.mjs Did you mean to import "ignore/index.js"?  ELIFECYCLE  Command failed with exit code 1.
1 replies