volatiletech / authboss

The boss of http auth.
MIT License
3.85k stars 207 forks source link

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

Closed siredwin closed 4 years ago

siredwin commented 4 years ago

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 thedataInjector. 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 commented 4 years ago

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

aarondl commented 4 years ago

@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!

siredwin commented 4 years ago

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.