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.

Async Middleware - No active Pinia

See original GitHub issue

Environment


  • Operating System: Linux
  • Node Version: v16.14.2
  • Nuxt Version: 3.0.0-27484505.9f6eff7
  • Package Manager: yarn@1.22.18
  • Builder: vite
  • User Config: vite, privateRuntimeConfig, publicRuntimeConfig, css, buildModules, intlify, vueuse
  • Runtime Modules: -
  • Build Modules: @pinia/nuxt@0.1.8, @vueuse/nuxt@8.2.4, @intlify/nuxt3@0.1.10

Reproduction

check-auth.global.ts:

import { useUserStore } from "~/stores/user";

export default defineNuxtRouteMiddleware(async () => {
    // check if user is authenticated by using cookie and pinia

    const session = useCookie('laravel_session').value || null
    const userStore = useUserStore();
    
    await userStore.fetchUser();

})

Describe the bug

getActivePinia was called with no active Pinia. Did you forget to install pinia? const pinia = createPinia() app.use(pinia) This will fail in production.

Using async middleware, pinia is not getting started.

Additional context

No response

Logs

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
typhoon11commented, Dec 9, 2022

Is this fixed @danielroe because the same problem continues to be in Stable version of nuxt 3

0reactions
serhezcommented, Jun 29, 2022

Are there any updates on this issue? I’m using RC 3 and this is still not working.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nuxt 3 - Async Middleware - No active Pinia #1212 - GitHub
const pinia = createPinia() app.use(pinia) This will fail in production. Using async middleware, pinia is not getting started. Additional information. No ...
Read more >
Vue: Can't access Pinia Store in beforeEnter vue-router
However, I don't have access to the Pinia Store, which doesn't seem to be initialized yet, although it is called before in the...
Read more >
Complex Vue 3 state management made easy with Pinia
Build a basic blog engine using Pinia, a state management tool for Vue apps, and its main features, including state, getters, and actions....
Read more >
Using Modules and Pinia to structure Nuxt 3 app
So basically Pinia works in all places no matter where you import it in your application. If you import it in the module,...
Read more >
Nuxt.js - Pinia
We added it to the context so you have access to it in asyncData() and fetch() : ... but if you need to...
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