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

RFC: getServerSession support for Websockets and other non-H3Event requests #981

Open
5 tasks
CeebDev opened this issue Jan 14, 2025 · 1 comment
Open
5 tasks
Labels
question A question about NuxtAuth

Comments

@CeebDev
Copy link

CeebDev commented Jan 14, 2025

Describe the feature

It'd be nice if getServerSession could be called with non-H3Event payloads, to allow all standardized req / res sources to get the server session. A prominent example of this are websockets

This is a reopen of #135

I use defineWebSocketHandler and can't authentificate peers

How would you implement this?

No response

Additional information

  • Would you be willing to help implement this feature?

Provider

  • AuthJS
  • Local
  • Refresh
  • New Provider
@CeebDev CeebDev added enhancement An improvement that needs to be added pending An issue waiting for triage labels Jan 14, 2025
@phoenix-ru
Copy link
Collaborator

I am not entirely sure what your usecase would be? New authjs can work with web-standard Request and Response, but that means having and exchanging cookies/etc.

The only solution I see that you can implement is to have a regular HTTP endpoint protected by nuxt-auth middleware, which would upgrade the connection to ws(s) protocol. As soon as the connection is upgraded, you exchange messages as usual, without any authentication/etc.
Because getServerSession returns expires, you can check if the Websocket connection has become unauthenticated for example on requests/randomly on interval/however you wish.

I don't see any other way and imho there is no other way.

@phoenix-ru phoenix-ru added question A question about NuxtAuth and removed enhancement An improvement that needs to be added pending An issue waiting for triage labels Jan 16, 2025
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