Description
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 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
Expected behavior
getCurrentUser
returns the user without hanging.
Actual behavior
getCurrentUser
not returning.
Additional information
Probably related to #1624.