Skip to content
Snippets Groups Projects

Fix: Guard problem

Merged Bayu Samudra requested to merge fix/gruard-error into staging
+ 3
3
@@ -30,7 +30,9 @@ func (g GuardMiddleware) Handle(next http.Handler) http.Handler {
if len(g.Role) > 0 {
authorization := r.Header.Get("Authorization")
if authorization == "" {
tokenSplit := strings.Split(authorization, " ")
if len(tokenSplit) != 2 {
g.Logger.Info("Unauthorized access detected")
w.WriteHeader(http.StatusBadRequest)
@@ -41,8 +43,6 @@ func (g GuardMiddleware) Handle(next http.Handler) http.Handler {
return
}
tokenSplit := strings.Split(authorization, " ")
if tokenSplit[0] != "Bearer" {
w.WriteHeader(http.StatusUnprocessableEntity)
payload := g.WrapperUtil.ErrorResponseWrap("authorization must be bearer token", nil)