N
Nuxt2mo ago
Nisthar

Uncaught SyntaxError: The requested module '/_nuxt/middleware/auth.global.ts' when restarting nuxt

I get this error in the browser console everytime i restart the nuxt server. when this happens the dev tools doesn't work and hmr also doesn't work. This is my middleware middleware/auth.global.ts
export default defineNuxtRouteMiddleware(async (to, from) => {
const allowedPaths = [
'/',
'/login',
'/signup',
'/forgot-password',
'/reset-password',
]
const { fetchUser, setUser } = useDirectusAuth();
const user = useDirectusUser();
if (!user.value) {
const user = await fetchUser();
setUser(user.value);
}
if (!user.value && !allowedPaths.includes(to.path)) {
return navigateTo("/login");
}
});
export default defineNuxtRouteMiddleware(async (to, from) => {
const allowedPaths = [
'/',
'/login',
'/signup',
'/forgot-password',
'/reset-password',
]
const { fetchUser, setUser } = useDirectusAuth();
const user = useDirectusUser();
if (!user.value) {
const user = await fetchUser();
setUser(user.value);
}
if (!user.value && !allowedPaths.includes(to.path)) {
return navigateTo("/login");
}
});
I comment the middleware and uncomment it again to fix the error. But if i restart the server or change .env file, it happens again.
1 Reply
Nisthar
NistharOP2mo ago
anyone know what could be causing this error?
Want results from more Discord servers?
Add your server