033082954a
- Rename Go module from onixbyte.com/message-converter-manifest to onixbyte.com/pipely - Replace shadcn UI with Material UI components across all pages - Add axios-based API client in shared/web-client with credentials management - Organise API calls into feature modules: auth, devices, deployments, artefacts, users - Add .env.example with VITE_API_BASE_URL pointing to pipely.onixbyte.com - Fix deprecated FormEvent → MouseEvent in dialog submit handlers
35 lines
823 B
Go
35 lines
823 B
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"onixbyte.com/pipely/internal/auth"
|
|
)
|
|
|
|
func AuthMiddleware(authSvc *auth.Service) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
authHeader := c.GetHeader("Authorization")
|
|
if authHeader == "" {
|
|
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "Authorisation header is missing"})
|
|
return
|
|
}
|
|
|
|
parts := strings.SplitN(authHeader, " ", 2)
|
|
if !(len(parts) == 2 && parts[0] == "Bearer") {
|
|
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "Invalid authorisation format"})
|
|
return
|
|
}
|
|
|
|
user, err := authSvc.ValidateToken(parts[1])
|
|
if err != nil {
|
|
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "Unauthorised: " + err.Error()})
|
|
return
|
|
}
|
|
|
|
c.Set("user", user)
|
|
c.Next()
|
|
}
|
|
}
|