diff --git a/internal/service/handlers/create_balance.go b/internal/service/handlers/create_balance.go index 0633938..1e85a64 100644 --- a/internal/service/handlers/create_balance.go +++ b/internal/service/handlers/create_balance.go @@ -65,6 +65,10 @@ func CreateBalance(w http.ResponseWriter, r *http.Request) { return } + for i := range referrals { + referrals[i].Status = data.StatusActive + } + ape.Render(w, newBalanceResponse(*balance, referrals)) } diff --git a/internal/service/handlers/middleware.go b/internal/service/handlers/middleware.go index a0fed56..6ba9e0f 100644 --- a/internal/service/handlers/middleware.go +++ b/internal/service/handlers/middleware.go @@ -5,8 +5,9 @@ import ( "net/http" "github.com/rarimo/decentralized-auth-svc/pkg/auth" - "github.com/rarimo/decentralized-auth-svc/resources" "github.com/rarimo/rarime-points-svc/internal/data/pg" + "gitlab.com/distributed_lab/ape" + "gitlab.com/distributed_lab/ape/problems" "gitlab.com/distributed_lab/kit/pgdb" "gitlab.com/distributed_lab/logan/v3" ) @@ -14,19 +15,19 @@ import ( func AuthMiddleware(auth *auth.Client, log *logan.Entry) func(http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - //claims, err := auth.ValidateJWT(r) - //if err != nil { - // log.WithError(err).Info("Got invalid auth or validation error") - // ape.RenderErr(w, problems.Unauthorized()) - // return - //} - // - //if len(claims) == 0 { - // ape.RenderErr(w, problems.Unauthorized()) - // return - //} - - ctx := CtxUserClaims([]resources.Claim{{Nullifier: r.Header.Get("nullifier")}})(r.Context()) + claims, err := auth.ValidateJWT(r) + if err != nil { + log.WithError(err).Info("Got invalid auth or validation error") + ape.RenderErr(w, problems.Unauthorized()) + return + } + + if len(claims) == 0 { + ape.RenderErr(w, problems.Unauthorized()) + return + } + + ctx := CtxUserClaims(claims)(r.Context()) next.ServeHTTP(w, r.WithContext(ctx)) }) }