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

DataInjector main cause for ("panic: ResponseWriter must be a ClientStateResponseWriter or UnderlyingResponseWriter") #296

Closed
siredwin opened this issue Jul 3, 2020 · 3 comments

Comments

@siredwin
Copy link

siredwin commented Jul 3, 2020

I am using the echo Framework.
I am at a point where I have to abandon AuthBoss or Echo for Go-chi.

I have found the cause of the problem though, it is the dataInjector. It somehow hijacks the context.
The LoadClientStateMiddleware is just ok.

I am going to try to modify it and see if it works.
If you can think of anything else wrong with it, let me know.

@siredwin
Copy link
Author

siredwin commented Jul 3, 2020

For now, I am foregoing the DataInjector middleware and using data := LayoutData(w, r) directly in my views.
So far so good.

@aarondl
Copy link
Member

aarondl commented Jul 3, 2020

@siredwin The problem is simple. Authboss functions require the http.ResponseWriter's underlying type to be an authboss.ClientStateReadWriter OR an authboss.UnderlyingResponseWriter. If it is not one of those two things it will break.

Echo is one of few frameworks that replace the http.ResponseWriter from the http.Server with its own thing. That means that the LoadClientStateMiddleware has to be positioned AFTER Echo's replacement of the response writer, so that middlewares and handlers receive the Authboss RW, and not the Echo RW.

Abandoning "Authboss or Echo for Go-chi" is an excellent idea. Chi does not replace the response writer and so is an excellent companion to Authboss. We use Authboss + Chi for our projects.

Good luck!

@aarondl aarondl closed this as completed Jul 3, 2020
@siredwin
Copy link
Author

siredwin commented Jul 3, 2020

I figured that much.
I think re-writing DataInjector into an echo middleware will be enough for now. It is working so far when I do it manually with data := LayoutData(w, r)

That also answers my question of if you chose chi example for that reason.

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

No branches or pull requests

2 participants