chore: update api v1 user context name

This commit is contained in:
Steven
2023-08-02 07:44:04 +08:00
parent 59a75c89eb
commit c26834e9cd
7 changed files with 20 additions and 21 deletions

View File

@ -15,6 +15,12 @@ import (
"github.com/pkg/errors"
)
const (
// The key name used to store user id in the context
// user id is extracted from the jwt token subject field.
UserIDContextKey = "user-id"
)
type claimsMessage struct {
Name string `json:"name"`
jwt.RegisteredClaims
@ -183,7 +189,7 @@ func JWTMiddleware(server *APIV1Service, next echo.HandlerFunc, secret string) e
}
// Stores userID into context.
c.Set(auth.UserIDContextKey, userID)
c.Set(UserIDContextKey, userID)
return next(c)
}
}