This repository has been archived on 2025-08-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
web-app-template/handler/middleware/user.go
2024-12-08 23:19:45 +01:00

23 lines
483 B
Go

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)
})
}
}