Skip to content

getCurrentUser loading infinitely when not always calling it in global middleware and having node_modules/.cache/vite cleared #1625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dword-design opened this issue May 6, 2025 · 0 comments

Comments

@dword-design
Copy link

dword-design commented 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 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');
});
  1. rm -rf node_modules/.cache/vite && pnpm dev
  2. 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.

@dword-design 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant