You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a global middleware and I'm conditionally checking auth state. When clearing the cache via nuxi cleanup and early exiting the middleware but calling getCurrentUser another navigation time, it will just load infinitely and not return. Actually it only happens when deleting the node_modules/.cache/vite dir.
When calling getCurrentUser always at the beginning however, it works as expected.
When rerunning nuxt dev it's working as expected.
Additional observation: Is only the case for a global middleware. When setting one via definePageMeta it's working as expected.
EDIT: It looks like global middlewares run in a different context than assigned middlewares. The initialUserMap variable is different in getCurrentUser vs. onIdTokenChanged, which is why the promise is never resolved.
// middleware/auth.global.js => ✅ Works
export default defineNuxtRouteMiddleware(async to => {
console.log('start');
await getCurrentUser();
console.log('end');
if (to.fullPath === '/') {
return;
}
});
// middleware/auth.global.js => ❌ Doesn't work
export default defineNuxtRouteMiddleware(async to => {
if (to.fullPath === '/') {
return;
}
console.log('start');
await getCurrentUser();
console.log('end');
});
rm -rf node_modules/.cache/vite && pnpm dev
Click on the login link. It will load infinitely and not navigate
The text was updated successfully, but these errors were encountered:
dword-design
changed the title
getCurrentUser loading infinitely when not always calling it in global middleware
getCurrentUser loading infinitely when not always calling it in global middleware and having node_modules/.cache/vite cleared
May 6, 2025
Reproduction
https://github.com/dword-design/demo-vuefire-getcurrentuser-infinitely
Steps to reproduce the bug
I have a global middleware and I'm conditionally checking auth state. When clearing the cache via nuxi cleanup and early exiting the middleware but calling getCurrentUser another navigation time, it will just load infinitely and not return. Actually it only happens when deleting the node_modules/.cache/vite dir.
When calling getCurrentUser always at the beginning however, it works as expected.
When rerunning nuxt dev it's working as expected.
Additional observation: Is only the case for a global middleware. When setting one via definePageMeta it's working as expected.
EDIT: It looks like global middlewares run in a different context than assigned middlewares. The
initialUserMap
variable is different ingetCurrentUser
vs.onIdTokenChanged
, which is why the promise is never resolved.rm -rf node_modules/.cache/vite && pnpm dev
Expected behavior
getCurrentUser
returns the user without hanging.Actual behavior
getCurrentUser
not returning.Additional information
Probably related to #1624.
The text was updated successfully, but these errors were encountered: