diff options
author | Santo Cariotti <santo@dcariotti.me> | 2025-04-08 14:37:33 +0200 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2025-04-08 14:39:13 +0200 |
commit | 1f0d9ec8452f15c27cd33c4e3874454c35993743 (patch) | |
tree | c453a31ae5eb823aaf48868eea9fc4daf65f108b /api/middleware/middleware.go | |
parent | c5b10e28b358308d8349b940af09f64368172f2e (diff) |
Use internal/pkg structure
Diffstat (limited to 'api/middleware/middleware.go')
-rw-r--r-- | api/middleware/middleware.go | 36 |
1 files changed, 0 insertions, 36 deletions
diff --git a/api/middleware/middleware.go b/api/middleware/middleware.go deleted file mode 100644 index 29ed8b6..0000000 --- a/api/middleware/middleware.go +++ /dev/null @@ -1,36 +0,0 @@ -package middleware - -import ( - "encoding/json" - "net/http" - - "github.com/boozec/rahanna/api/auth" -) - -func AuthMiddleware(next http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - tokenString := r.Header.Get("Authorization") - - payloadMap := map[string]string{"error": "unauthorized"} - payload, _ := json.Marshal(payloadMap) - - if tokenString == "" { - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusUnauthorized) - - w.Write([]byte(payload)) - return - } - - _, err := auth.ValidateJWT(tokenString) - if err != nil { - w.WriteHeader(http.StatusUnauthorized) - - payload, _ := json.Marshal(payloadMap) - - w.Write([]byte(payload)) - return - } - next.ServeHTTP(w, r) - }) -} |