encore icon indicating copy to clipboard operation
encore copied to clipboard

Middleware Data and Redirection without Raw. | Encore Port of Better Auth

Open solarsoft0 opened this issue 11 months ago • 7 comments

Related PR: https://github.com/encoredev/encore/pull/1631?new_mergebox=true

First, the way middleware works makes it a great fit for TypeScript to shine in encore.ts, unlike how it is required to be expressed in Go. The arrangement also complements this.

I decided to port Better-Auth to support Encore natively. but, here is the blocker delaying progress without resorting to api.raw, as I want to leverage all of Encore's benefits:

Blocker:

  • The ability to set and get data in middleware.
  • The ability to redirect either in a handler or in middleware.

I would have asked for Zod support, but I noticed that removing Zod resolved the issue and made it more Encore-native. While I suspect there might still be some limitations, things are moving smoothly so far. I also aim to use this issue to track any problems if I come across any.

I believe this will be a valuable contribution to the community at large, enabling developers to quickly spin up authentication for their projects without sacrificing what makes Encore interesting or relying on external services. You can read more about the motivation for this project here: https://github.com/solarsoft0/better-auth/issues/1

I currently have a copy in my personal project that I am working with, and I plan to sync it with the repo once things are stable. Considering the urgency of getting authentication out of the way, I may resort to a forklift migration, which I would rather avoid. I would greatly appreciate it if we could resolve these issues as soon as possible.

Thank you for making this amazing framework!

solarsoft0 avatar Jan 06 '25 10:01 solarsoft0

I think https://github.com/encoredev/encore/pull/1631 should solve both the problems. Redirects will be possible through custom status code and setting headers

fredr avatar Jan 07 '25 08:01 fredr

yeah, I am currently using a forklift migration, and it feels like a black hole. maybe I'm getting too used to encore, I would love us to see this through as soon as we can, I will keep this issue up, to track anything else I may come across until we have encore-better-auth. thanks! @fredr.

solarsoft0 avatar Jan 07 '25 12:01 solarsoft0

The middleware pr have been released now (version 1.45.3), you can update encore by running encore version update

fredr avatar Jan 08 '25 17:01 fredr

Hello,

@solarsoft0 what is the status of Encore.ts & Better-auth integration?

carere avatar Feb 15 '25 19:02 carere

@carere just seeing this, i have been busy with other stuff, I am just about to pick this up again. Tomorrow we should have an update as regards this.

solarsoft0 avatar Feb 23 '25 13:02 solarsoft0

@solarsoft0, is there any news about better-auth and encore integration?

mariolim96 avatar Mar 07 '25 11:03 mariolim96

yes! https://github.com/solarsoft0/encore-better-auth/pull/2 this PR will seal it up.

Image

solarsoft0 avatar Mar 08 '25 13:03 solarsoft0