atinux / nuxt-auth-utils

Add Authentication to Nuxt applications with secured & sealed cookies sessions.
MIT License
974 stars 91 forks source link

Plugin types break other Vue.js plugin helpers #158

Closed FabienMotte closed 2 months ago

FabienMotte commented 2 months ago

When using the nuxt-auth-utils module and starting Nuxt, two imports are generated in the .nuxt/types/plugins.d.ts file:

  /* ... */

  InjectionType<typeof import("../../node_modules/.pnpm/nuxt-auth-utils@0.3.5_magicast@0.3.5_rollup@4.21.2/node_modules/nuxt-auth-utils/dist/runtime/app/plugins/session.client.js").default> &
  InjectionType<typeof import("../../node_modules/.pnpm/nuxt-auth-utils@0.3.5_magicast@0.3.5_rollup@4.21.2/node_modules/nuxt-auth-utils/dist/runtime/app/plugins/session.server.js").default> &

  /* ... */

These two imports don't resolve because the files dist/runtime/app/plugins/session.client.d.ts and dist/runtime/app/plugins/session.server.d.ts are empty. This breaks the typing of other plugins that provide a helper on the NuxtApp instance, such as trpc-nuxt:

const { $trpc } = useNuxtApp() // '$trpc' is of type 'unknown'

Using export default {} in the session.client.d.ts and session.server.d.ts files solves the issue.