This commit is contained in:
2024-12-04 23:15:40 +01:00
parent bbcdbf7a01
commit b9d50d986f
2 changed files with 43 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
package middleware
import (
"me-fit/service"
"net/http"
)
func UserAuth(service *service.AuthService) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Check the user is logged in
sessionToken := r.Header.Get("X-Session-Token")
if sessionToken == "" {
http.Error(w, "Unauthorized", http.StatusUnauthorized)
return
}
next.ServeHTTP(w, r)
})
}
}