Fix issues with JWT auth

This commit is contained in:
Vikram Rangnekar
2019-11-15 01:35:19 -05:00
parent 51c5f037f4
commit 396f4bcfd8
6 changed files with 7 additions and 73 deletions

View File

@ -95,8 +95,11 @@ func jwtHandler(next http.HandlerFunc) http.HandlerFunc {
} else {
ctx = context.WithValue(ctx, userIDKey, claims.Subject)
}
next.ServeHTTP(w, r.WithContext(ctx))
return
}
next.ServeHTTP(w, r)
}
}

View File

@ -77,16 +77,14 @@ func apiv1Http(w http.ResponseWriter, r *http.Request) {
}
b, err := ioutil.ReadAll(io.LimitReader(r.Body, maxReadBytes))
defer r.Body.Close()
if err != nil {
logger.Err(err).Msg("failed to read request body")
errorResp(w, err)
return
}
defer r.Body.Close()
err = json.Unmarshal(b, &ctx.req)
if err != nil {
logger.Err(err).Msg("failed to decode json request body")
errorResp(w, err)
@ -109,10 +107,10 @@ func apiv1Http(w http.ResponseWriter, r *http.Request) {
if err != nil {
logger.Err(err).Msg("failed to handle request")
errorResp(w, err)
return
}
}
func errorResp(w http.ResponseWriter, err error) {
w.WriteHeader(http.StatusBadRequest)
json.NewEncoder(w).Encode(gqlResp{Error: err.Error()})
}

View File

@ -169,6 +169,7 @@ func routeHandler() http.Handler {
mux := http.NewServeMux()
mux.Handle("/api/v1/graphql", withAuth(apiv1Http))
if conf.WebUI {
mux.Handle("/", http.FileServer(rice.MustFindBox("../web/build").HTTPBox()))
}