Files
Laterna/cmd/internal/middleware/auth.go
T
Siesta 57592b4987 feat: a lot
i did a lot of work, and i also forgot to add commits regularly. I added the controller routes to create and delete controllers, improved error handling und improved the authentification process. I'm gonna add an websocket next and then I should be hopefully done with the foundations of this project. I may also add anviewControllers route which respons with every available controller
2025-07-20 18:31:38 +02:00

19 lines
451 B
Go

package middleware
import (
"net/http"
"github.com/siestaw/laterna/server/cmd/internal/db"
"github.com/siestaw/laterna/server/cmd/utils"
)
func WithAdminAuth(handlerFunc http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
token := r.Header.Get("Authorization")
if !db.IsAdmin(token) {
utils.HTTPResponseHandler(w, r, http.StatusUnauthorized, "Invalid token")
return
}
handlerFunc(w, r)
}
}