fix: watchlist updated_at and unified auth middleware

This commit is contained in:
2026-05-02 17:53:08 +02:00
committed by Mikkel Elvers
parent 5940d7828a
commit e5c32fd154
5 changed files with 20 additions and 21 deletions

View File

@@ -58,8 +58,8 @@ func RequireAuth(next http.Handler) http.Handler {
}
}
user, ok := r.Context().Value(ctxpkg.UserKey).(*database.User)
if !ok || user == nil {
user := GetUser(r.Context())
if user == nil {
if strings.HasPrefix(r.URL.Path, "/api/") {
w.Header().Set("HX-Redirect", "/login")
http.Error(w, "Unauthorized", http.StatusUnauthorized)
@@ -73,8 +73,8 @@ func RequireAuth(next http.Handler) http.Handler {
})
}
func GetUser(ctx interface{}) *database.User {
user, ok := ctx.(*database.User)
func GetUser(ctx context.Context) *database.User {
user, ok := ctx.Value(ctxpkg.UserKey).(*database.User)
if !ok {
return nil
}