fix: resolve context key cycle for admin check
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"mal/internal/db"
|
||||
webcontext "mal/web/context"
|
||||
"mal/web/shared/admin"
|
||||
)
|
||||
|
||||
@@ -13,7 +14,7 @@ func IsAdmin(user *database.User) bool {
|
||||
|
||||
func RequireAdmin(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
user, ok := r.Context().Value(UserContextKey).(*database.User)
|
||||
user, ok := r.Context().Value(webcontext.UserKey).(*database.User)
|
||||
if !ok || user == nil {
|
||||
http.Redirect(w, r, "/login", http.StatusFound)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user