question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Middleware + pinia not working

See original GitHub issue

Environment

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:open
  • Created 10 months ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
manniLcommented, Nov 14, 2022

@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

0reactions
manniLcommented, Dec 9, 2022

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found