Middleware + pinia not working
See original GitHub issueEnvironment
middleware
Reproduction
middleware
Describe the bug
When I reload the page, it throws me to the authorization page, although the user is authorized
import { useAuthStore } from '~/store/auth';
export default defineNuxtRouteMiddleware(async () => {
const { loggedIn } = useAuthStore();
if (!loggedIn) {
return navigateTo('/auth');
}
});
Additional context
No response
Logs
No response
Issue Analytics
- State:
- Created 10 months ago
- Comments:11 (4 by maintainers)
Top Results From Across the Web
Nuxt 3 - Async Middleware - No active Pinia #1212 - GitHub
I've tried using the Nuxt Context to provide the $pinia instance, but its undefined due to the fact that Middleware is loaded before...
Read more >Using a store outside of a component - Pinia
The easiest way to ensure this is always applied is to defer calls of useStore() by placing them inside functions that will always...
Read more >Using Modules and Pinia to structure Nuxt 3 app
These modules can contain their own components, composables, pages, plugins, and even a server middleware. By having all this modular ...
Read more >Vue: Can't access Pinia Store in beforeEnter vue-router
To fix this problem I just called the useStore() function inside the function provided by Vue(beforeEach) and it worked.
Read more >Vue.js, Pinia, Vue Query, Axios Interceptors JWT Authentication
js community has come to realize that most state management libraries including Vuex and Pinia work really well with client states but do...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@maksimdrosdov Please be aware that a full-blown project is no reproduction 🙈
The goal is to have as little “moving pieces” as possible and a project that is as small as possible to reproduce the bug so contributors can pin it down easily and it is not caused by any custom userland logic
@typhoon11 Please provide a repository or use Stackblitz or Codesandbox as linked above. This is the best way to make it easy for maintainers to help you. I highly recommend to read the linked paragraph above.