Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find package 'next-auth' when importing in server using '#auth' #877

Closed
FabianClemenz opened this issue Aug 23, 2024 · 5 comments
Closed
Labels
provider-authjs An issue with the authjs provider question A question about NuxtAuth

Comments

@FabianClemenz
Copy link

Environment

Working directory: /frontend                                                                                                                                                                                               09:37:31
Nuxt project info: (copied to clipboard)                                                                                                                                                                                                                                  09:37:31

------------------------------
- Operating System: Darwin
- Node Version:     v22.6.0
- Nuxt Version:     3.12.4
- CLI Version:      3.12.0
- Nitro Version:    2.9.7
- Package Manager:  [email protected]
- Builder:          -
- User Config:      compatibilityDate, devtools, modules, auth
- Runtime Modules:  @nuxt/[email protected], @sidebase/[email protected], @nuxt/[email protected], @pinia/[email protected]
- Build Modules:    -
------------------------------

Reproduction

Reproduction link

Describe the bug

I'm using nuxt-auth for JWT authentication with my own backend. I wanted to create a middleware, which adds the accessToken to every request.

As seen in the reproduction, i followed exactly the guide here https://auth.sidebase.io/guide/authjs/server-side/jwt-access#jwt-access but i get the error:

 WARN  "next-auth/core" is imported by "node_modules/@sidebase/nuxt-auth/dist/runtime/server/services/authjs/nuxtAuthHandler.mjs", but could not be resolved – treating it as an external dependency.                                                                     09:49:24


 WARN  "next-auth/jwt" is imported by "node_modules/@sidebase/nuxt-auth/dist/runtime/server/services/authjs/nuxtAuthHandler.mjs", but could not be resolved – treating it as an external dependency.                                                                      09:49:24

✔ Nuxt Nitro server built in 194 ms                                                                                                                                                                                                                                nitro 09:49:24

 ERROR  [worker reload] [worker init] Cannot find package 'next-auth' imported from /frontend/.nuxt/dev/index.mjs            

Additional context

No response

Logs

No response

@FabianClemenz FabianClemenz added bug A bug that needs to be resolved pending An issue waiting for triage labels Aug 23, 2024
@zoey-kaiser
Copy link
Member

Hi @FabianClemenz 👋

Please ensure you are using [email protected] or earlier. In the subsequent version, they made a breaking change, where they did not expose the core anymore!

You can see more on this in our docs: https://auth.sidebase.io/guide/authjs/quick-start

@zoey-kaiser zoey-kaiser added provider-authjs An issue with the authjs provider question A question about NuxtAuth and removed pending An issue waiting for triage bug A bug that needs to be resolved labels Aug 23, 2024
@FabianClemenz
Copy link
Author

Hi @zoey-kaiser

i'm not using the AuthJS Provider but the refresh provider. Do i also need to install it?

@zoey-kaiser
Copy link
Member

zoey-kaiser commented Aug 23, 2024

i'm not using the AuthJS Provider but the refresh provider. Do i also need to install it?

The server-side functions are currently only supported by the authjs provider, which is why it prompts you to install the package. The local provider only supports client-side fetching.
We have an open PR at the moment, which adds support for server-side token and session fetching for the local provider (#855)

Until it is released, you can fetch the Token manually on the server-side using:

Get Token:

export default defineEventHandler(() => {
  const rawToken = getCookie(event, 'auth.Token') // Or you custom cookie name
  const formattedToken = `Bearer ${rawToken}`
})

@zoey-kaiser
Copy link
Member

If this works for you! I would close this Issue, feel free to comment in #854 where we previously discussed server-side access for the local provider 🤗

@FabianClemenz
Copy link
Author

@zoey-kaiser ok i c - thanks for clarifying this!

i think i can get it working from here - thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
provider-authjs An issue with the authjs provider question A question about NuxtAuth
Projects
None yet
Development

No branches or pull requests

2 participants