Skip to content

Commit

Permalink
Paste active referral code status on balance creation, revert mocked …
Browse files Browse the repository at this point in the history
…auth
  • Loading branch information
violog committed Jun 14, 2024
1 parent fe173c2 commit 57f7218
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
4 changes: 4 additions & 0 deletions internal/service/handlers/create_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
29 changes: 15 additions & 14 deletions internal/service/handlers/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,29 @@ 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"
)

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))
})
}
Expand Down

0 comments on commit 57f7218

Please sign in to comment.