Reorganize handlers

This commit is contained in:
2024-11-03 17:41:17 +01:00
parent 72680abdf4
commit dfd9544fba
10 changed files with 273 additions and 239 deletions

View File

@@ -127,17 +127,15 @@ func RefreshToken(authService *auth.SessionService) http.HandlerFunc {
}
// GetCurrentUser returns the currently authenticated user
func GetCurrentUser(db *db.DB) http.HandlerFunc {
func (h *BaseHandler) GetCurrentUser(db *db.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// Get user claims from context (set by auth middleware)
claims, err := auth.GetUserFromContext(r.Context())
if err != nil {
http.Error(w, "Unauthorized", http.StatusUnauthorized)
ctx, ok := h.getContext(w, r)
if !ok {
return
}
// Get user from database
user, err := db.GetUserByID(claims.UserID)
user, err := db.GetUserByID(ctx.UserID)
if err != nil {
http.Error(w, "User not found", http.StatusNotFound)
return