Added ExpenseAdder Endpoint

This commit is contained in:
2026-03-01 12:46:40 +01:00
parent 6a974cbbf1
commit 54a8292234
6 changed files with 177 additions and 29 deletions

View File

@@ -5,6 +5,8 @@ import (
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"net/http"
"shap-planner-backend/auth"
"github.com/google/uuid"
)
@@ -31,3 +33,17 @@ func HashToken(token string) string {
hash := sha256.Sum256([]byte(token))
return hex.EncodeToString(hash[:])
}
func IsLoggedIn(w http.ResponseWriter, r *http.Request) (*auth.Claims, bool) {
claimsRaw := r.Context().Value(auth.UserContextKey)
if claimsRaw == nil {
http.Error(w, "No claims in context", http.StatusUnauthorized)
return nil, false
}
claims, ok := claimsRaw.(*auth.Claims)
if !ok {
http.Error(w, "Invalid claims", http.StatusUnauthorized)
return nil, false
}
return claims, true
}