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

Inside NuxtAuthHandler we cannot use useRequestEvent and useRequestHeader #907

Open
agracia-foticos opened this issue Sep 12, 2024 · 7 comments
Labels
question A question about NuxtAuth

Comments

@agracia-foticos
Copy link

Environment

  • Operating System: Linux
  • Node Version: v22.7.0
  • Nuxt Version: 3.13.1
  • CLI Version: 3.13.1
  • Nitro Version: 2.9.7
  • Package Manager: [email protected]
  • Builder: -
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

we cannot reproduction

Describe the bug

We are trying to use useRequestEvent and useRequestHeaders to access the request cookies but they are not available.

Also we try to access $fetch('/api/session', {method:'GET'}) (this is an access to H3 session) but the cookies not are sending.

There is any option to send cookies to NuxtAuthHandler?

Additional context

No response

Logs

No response

@agracia-foticos agracia-foticos added bug A bug that needs to be resolved pending An issue waiting for triage labels Sep 12, 2024
@phoenix-ru
Copy link
Collaborator

Could you please elaborate a bit? What are you trying to achieve? Some code examples would be nice to understand the problem, thanks

@agracia-foticos
Copy link
Author

We manage a session with https://h3.unjs.io/examples/handle-session outside nuxt-auth.

This session its bassed on cookies, this session contains a field called createdAt, this value we must checked in JWT session, because its expiration session of auth.

This field can be changed, this is the reason because we want read it in JWT function, but NuxtAuthHandler doesnt have access to :

  • useRequestEvent to return cookies object
  • useRequestHeaders to access headers and cookies
  • $fetch('/api/session', {method:'GET'}) because this is a endpoint to access H3 cookie session, but we havent the cookies to pass to endpoint hence this session its blank session

@phoenix-ru
Copy link
Collaborator

Can you provide at least a minimal reproduction? I have hard time following your usecase. You can use CredentialsProvider with hardcoded credentials similar to playground-authjs:
https://github.com/sidebase/nuxt-auth/blob/main/playground-authjs/server/api/auth/%5B...%5D.ts

You can base it off playground-authjs to save some time or from one of the templates below (from bot comment).

NuxtAuthHandler normally works according to Authjs flow: https://authjs.dev/getting-started/installation#configure

@phoenix-ru phoenix-ru added needs-reproduction Action needed: A valid reproduction of the issue needs to be added question A question about NuxtAuth and removed bug A bug that needs to be resolved pending An issue waiting for triage labels Sep 12, 2024
Copy link

Hello 👋

Please provide a reproduction for this issue 🙏

How can I create a reproduction?

Please use one of the following links to reproduce your issue.

Please ensure that the reproduction is as minimal as possible. This will allow us to isolate the issue as best as possible.

Here are some more amazing posts about the importance of reproductions:

@agracia-foticos
Copy link
Author

https://stackblitz.com/edit/nuxt-starter-embl4u @phoenix-ru here you are a reproduction, but we cant test it because stackblitz are very slow compiling

image

you can see in plugins/01.session.ts we initialize the H3 cookie session.

In server/routes/api/session.get.ts we retreive this H3 cookie session.

In server/api/auth/[...].ts in JWT validation, we want to check this H3 cookie session, but returns blank, not the session created in plugin, because in NuxtAuthHandler seems that cookies arent accesible

@phoenix-ru
Copy link
Collaborator

Tried to check the reproduction but you're right - Stackblitz is slow - or support of Stackblitz in Nuxt is broken. Unfortunately, need to de-prioritize in favor of #883

@phoenix-ru phoenix-ru removed the needs-reproduction Action needed: A valid reproduction of the issue needs to be added label Sep 12, 2024
@agracia-foticos
Copy link
Author

@phoenix-ru don't worry, prioritize #883, We can advance our development on the other hand, this issue is not a priority. In a few days I will contact you again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A question about NuxtAuth
Projects
None yet
Development

No branches or pull requests

2 participants