nuxt-3-auth icon indicating copy to clipboard operation
nuxt-3-auth copied to clipboard

Pinia v3 support

Open amery opened this issue 9 months ago • 5 comments

I'm trying to use this module but just by enabling the module (after @pinia/nuxt) everything explodes.

e.g. https://github.com/amery/nuxt-3-auth-test

  modules: [
    '@nuxt/eslint',
    '@pinia/nuxt',
    '@trandaison/nuxt-3-auth',
  ],
  auth: {
    debug: !isProduction,
  },

I'm guessing doing useAuthStore() in the plugin constructor is the problem, but... why doesn't it fail for you too?

500
[🍍]: "getActivePinia()" was called but there was no active Pinia. Are you trying to use a store before calling "app.use(pinia)"? See https://pinia.vuejs.org/core-concepts/outside-component-usage.html for help. This will fail in production.

See https://pinia.jsjs.org/core-concepts/outside-component-usage.html for help.
This will fail in production.
at useStore (/xxx/node_modules/pinia/dist/pinia.mjs:1735:19)
at new AuthStorage (/xxx/node_modules/@trandaison/nuxt-3-auth/dist/runtime/services/AuthStorage.js:25:60)
at new Auth (/xxx/node_modules/@trandaison/nuxt-3-auth/dist/runtime/plugin.js:8:23)
at /xxx/node_modules/nuxt/dist/app/nuxt.js:143:60)
at fn (/xxx/node_modules/nuxt/dist/app/nuxt.js:225:44)
at Object.callAsync (/xxx/node_modules/unctx/dist/index.mjs:68:55)
at /xxx/node_modules/nuxt/dist/app/nuxt.js:228:56)
at Object.runWithContext (/xxx/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:3977:18)
at callWithNuxt (/xxx/node_modules/nuxt/dist/app/nuxt.js:228:24) 
$ pnpm nuxt info
[ nuxi  22:30:41] Working directory: /xxx
Nuxt project info: 

------------------------------
- Operating System: Linux
- Node Version:     v22.14.0
- Nuxt Version:     3.16.0
- CLI Version:      3.22.5
- Nitro Version:    2.11.6
- Package Manager:  [email protected]
- Builder:          -
- User Config:      compatibilityDate, devtools, srcDir, modules, auth, eslint
- Runtime Modules:  @nuxt/[email protected], @pinia/[email protected], @trandaison/[email protected]
- Build Modules:    -
------------------------------

👉 Report an issue: https://github.com/nuxt/nuxt/issues/new?template=bug-report.yml
👉 Suggest an improvement: https://github.com/nuxt/nuxt/discussions/new
👉 Read documentation: https://nuxt.com

$ pnpm info
[email protected] | Proprietary | deps: 7 | versions: 1
My epic Nuxt.js project

dist
.tarball: https://registry.npmjs.org/nuxt-app/-/nuxt-app-1.0.0.tgz
.shasum: 2d7029cb4779811b818e3719fd6c5c69c531df19
.integrity: sha512-4cpUhxoXtreIHkzZVIVM2KwhGPC9viagHByyc2pCO2n98RJfU+fYh+ApFCUz/KOL6At5h2JDRTyDNN55zMCEKw==
.unpackedSize: 313.2 kB

dependencies:
cross-env: ^5.2.0   firebase: ^5.7.0    nuxt: ^2.0.0        vuexblaze: ^0.0.3   
faker: ^4.1.0       nuxt-fire: ^1.2.1   random-name: ^0.1.2 

maintainers:
- ishiijp <[email protected]>

dist-tags:
latest: 1.0.0 

published over a year ago by ishiijp <[email protected]>
$ pnpm version
{
  npm: '11.1.0',
  node: '22.14.0',
  acorn: '8.14.0',
  ada: '2.9.2',
  amaro: '0.3.0',
  ares: '1.34.4',
  brotli: '1.1.0',
  cjs_module_lexer: '1.4.1',
  cldr: '46.0',
  icu: '76.1',
  llhttp: '9.2.1',
  modules: '127',
  napi: '10',
  nbytes: '0.1.1',
  ncrypto: '0.0.1',
  nghttp2: '1.64.0',
  nghttp3: '1.6.0',
  ngtcp2: '1.10.0',
  openssl: '3.0.15+quic',
  simdjson: '3.10.1',
  simdutf: '6.0.3',
  sqlite: '3.47.2',
  tz: '2024b',
  undici: '6.21.1',
  unicode: '16.0',
  uv: '1.49.2',
  uvwasi: '0.0.21',
  v8: '12.4.254.21-node.22',
  zlib: '1.3.0.1-motley-82a5fec'
}

amery avatar Mar 10 '25 22:03 amery

I had to downgrade @pinia/nuxt all the way down to 0.7.0 for the plugin to work

amery avatar Mar 10 '25 23:03 amery

Hi @amery,

I've check your repository. I believe this issue can be solved by create a store src/stores/index.ts in order to active the pinia stores. I've seen this before in the pinia or nuxt documentation, but I can't remember where. But give it a try and let me know if it works.

trandaison avatar Mar 11 '25 03:03 trandaison

Unfortunately, introducing a dummy store doesn't make pinia/nuxt initialize things before you use them. And... why did you close the issue?

amery avatar Mar 11 '25 03:03 amery

Thanks for your feedback! I confirm that it's not working with pinia 3.0 yet. It takes time to investigate and release a version, please using pinia 2.3 while waiting for the new version.

trandaison avatar Mar 11 '25 04:03 trandaison

For future visitors, these are the last compatible versions:

{
"@pinia/nuxt": "^0.7.0",
"@trandaison/nuxt-3-auth": "^0.1.7",
"pinia": "^2.3.1",
"pinia-plugin-persistedstate": "^4.1.3"
}

amery avatar Mar 11 '25 17:03 amery

FYI . There is a bug present in [email protected] https://github.com/vuejs/pinia/discussions/2884 which isn't going to be fixed because vue3 users shall move to pinia v3.

Any plan to work on this migration? Would a PR to switch to pinia@3 be welcomed? Are there existing branches or forks using pinia@3?

amery avatar Jun 01 '25 20:06 amery

@amery Thanks for your information. PRs are welcome!

trandaison avatar Jun 02 '25 02:06 trandaison

@amery This authentication module uses Pinia to manage both the logged-in state and user data as reactive store values. However, with Pinia v3.x, accessing the store outside of the setup() function is no longer supported. As a result, I need to refactor the module accordingly.

Please note that this update may introduce breaking changes, and it will take some time to complete the transition.

In the meantime, contributions are very welcome!

trandaison avatar Jun 02 '25 03:06 trandaison

@amery Please update to v0.2.0

trandaison avatar Jun 02 '25 04:06 trandaison

@amery Please update to v0.2.0

Oh, that was quick :D THANK YOU

amery avatar Jun 02 '25 14:06 amery