25 lines
606 B
Go
25 lines
606 B
Go
package rest
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"log/slog"
|
||
|
|
"net/http"
|
||
|
|
|
||
|
|
"goAuth/internal/csrf"
|
||
|
|
)
|
||
|
|
|
||
|
|
func (h *Handler) superuser(next http.Handler) http.Handler {
|
||
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||
|
|
u := userFromRequest(r)
|
||
|
|
if u == nil || !u.IsAdmin {
|
||
|
|
writeError(w, http.StatusForbidden, "forbidden")
|
||
|
|
return
|
||
|
|
}
|
||
|
|
next.ServeHTTP(w, r)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
func (h *Handler) refreshCsrf(w http.ResponseWriter) {
|
||
|
|
if _, err := csrf.UpdateCsrf(w, h.cfg.Cookies.CsrfName, h.cfg.Cookies.Secure); err != nil {
|
||
|
|
slog.Error("refresh csrf", slog.String("op", "rest.refreshCsrf"), slog.Any("error", err))
|
||
|
|
}
|
||
|
|
}
|