Effect-TS / effect

An ecosystem of tools to build robust applications in TypeScript
https://effect.website
MIT License
7.69k stars 244 forks source link

From Discord: Setting response cookies from RPC calls #2922

Open effect-bot opened 5 months ago

effect-bot commented 5 months ago

Summary

Summary:

Pawelblaszczyk is experimenting with an RPC setup similar to the minimal example provided in the Effect-TS ecosystem and is looking for guidance on setting cookies on RPC responses. Datner_ initially suggests using the Cookies module but mentions that cookie-based authentication doesn't typically fit the RPC model. Instead, token-based authentication is recommended.

Pawelblaszczyk shares that he has used cookie-based authentication with other RPC solutions like tRPC, Next.js actions, and even gRPC. Datner_ acknowledges this but notes that these solutions generally recommend token-based authentication.

Pawelblaszczyk points out that some modern frameworks like Next.js and Astro recommend cookies for authentication, and mentions that the library he uses for authentication (Lucia) also recommends cookies.

Datner_ agrees that better support for cookie-based authentication should be considered in the Effect-TS ecosystem and suggests opening an issue for this feature request. Pawelblaszczyk agrees to do so when he has time.

Key Takeaways:

  1. Current State of RPC in Effect-TS: The Effect-TS RPC setup doesn't natively support cookie-based authentication and generally recommends token-based authentication.
  2. Community Feedback: There is a growing interest in cookie-based authentication, as evidenced by other frameworks and libraries.
  3. Future Improvements: There is a suggestion to open an issue for better support for cookie-based authentication in the Effect-TS ecosystem.
  4. Practical Advice: For now, users can use the platform module to implement cookie-based authentication, although a more streamlined API might be developed in the future.
  5. Evolving Standards: The discussion highlights that the RPC module in Effect-TS is still evolving, and community feedback is valuable for its development.

Discord thread

https://discord.com/channels/795981131316985866/1247188136832798742

datner commented 5 months ago

Please refer to the thread since this is not the best representation of it and the key takeaways here are useless

pawelblaszczyk5 commented 5 months ago

Per further discussion, this can be solved pretty straightforward:

HttpServer.app.appendPreResponseHandler((req, res) =>
        HttpServer.response.setCookie(res, "bla", "blu")
      );

Only problem is this one isn't working in stream RPC handler, that's what left to investigate here