modified: serv_nginx/api_bb/pkg/middleware/auth.go
add some logs on debug level
This commit is contained in:
@@ -98,6 +98,9 @@ func RequireAuth(next http.Handler) http.Handler {
|
|||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
logger := logger.Get()
|
logger := logger.Get()
|
||||||
userID := r.Context().Value(UserIDKey)
|
userID := r.Context().Value(UserIDKey)
|
||||||
|
logger.Debug("RequireAuth method")
|
||||||
|
logger.Debug("Extracted user ID from token",
|
||||||
|
zap.Any("user_id", userID))
|
||||||
|
|
||||||
if userID == nil {
|
if userID == nil {
|
||||||
logger.Warn("Authentication required but no user ID in context")
|
logger.Warn("Authentication required but no user ID in context")
|
||||||
@@ -114,6 +117,9 @@ func RequireAuth(next http.Handler) http.Handler {
|
|||||||
func GetUserFromContext(ctx context.Context) (*models.User, bool) {
|
func GetUserFromContext(ctx context.Context) (*models.User, bool) {
|
||||||
logger := logger.Get()
|
logger := logger.Get()
|
||||||
user, ok := ctx.Value(UserKey).(*models.User)
|
user, ok := ctx.Value(UserKey).(*models.User)
|
||||||
|
logger.Debug("GetUserFromContext method")
|
||||||
|
logger.Debug("Extracted user ID from token",
|
||||||
|
zap.Any("user_id", user.ID))
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
logger.Debug("No user found in context")
|
logger.Debug("No user found in context")
|
||||||
|
|||||||
Reference in New Issue
Block a user