Skip to content

Conversation

@hay-kot
Copy link
Collaborator

@hay-kot hay-kot commented Dec 6, 2025

What this PR does / why we need it:

When users log out and a different user logs in, category and other user-specific data from the previous user was persisting and displaying incorrectly. This was caused by:

  1. Module-level refs in store composables that persist across the entire application lifecycle
  2. Nuxt's useAsyncData cache using static keys without user context
  3. The existing flushStore() function had a bug - it created a new ref instead of clearing the existing one

Changes:

  • Fixed flushStore() in use-store-factory.ts to properly clear the ref value (store.value = [] instead of store = ref([]))
  • Added resetXxxStore() functions to all 9 store modules (category, tag, food, label, tool, cookbook, household, unit, user)
  • Created clearAllStores() function in store/index.ts that calls all reset functions
  • Updated signOut() in use-auth-backend.ts to call clearAllStores() and clearNuxtData() on logout

Which issue(s) this PR fixes:

Fixes #5513

Testing

To test this fix:

  1. Log in as User A and navigate to view categories
  2. Log out
  3. Log in as User B (different group/household)
  4. Verify User B sees their own categories immediately without requiring a hard refresh
  5. Repeat switching between users to confirm data is properly cleared each time

Module-level store refs were persisting across user sessions, causing
categories and other user-specific data from one user to appear for
another user after login. This was particularly problematic as it
affected users across different devices.

- Fix flushStore() in use-store-factory.ts to clear ref value instead of
  creating a new ref
- Add reset functions to all store modules (category, tag, food, label,
  tool, cookbook, household, unit, user)
- Add clearAllStores() function to reset all stores at once
- Call clearAllStores() and clearNuxtData() on signOut to clear both
  module-level refs and Nuxt's useAsyncData cache
@github-actions github-actions bot added the bugfix label Dec 6, 2025
Copy link
Collaborator

@michael-genson michael-genson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@michael-genson michael-genson merged commit 05f648d into mealie-next Dec 6, 2025
15 checks passed
@michael-genson michael-genson deleted the fix/clear-stores-on-logout branch December 6, 2025 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] - Categories from different account/user showing after login

3 participants