mirror of
https://github.com/kaaninchen/Laterna.git
synced 2026-09-17 19:12:48 +00:00
20 lines
442 B
Go
20 lines
442 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.ErrorResponse(w, http.StatusUnauthorized, "Invalid token")
|
|
return
|
|
}
|
|
handlerFunc(w, r)
|
|
}
|
|
}
|