modified: serv_nginx/api_bb/pkg/middleware/auth.go
start end add on debug level logger
This commit is contained in:
@@ -26,6 +26,7 @@ func AuthMiddleware(jwtService service.JWTService, userRepo repository.UserRepos
|
|||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
var tokenString string
|
var tokenString string
|
||||||
logger := logger.Get()
|
logger := logger.Get()
|
||||||
|
logger.Debug("authMiddleware Start")
|
||||||
|
|
||||||
// Пробуем получить токен из заголовка Authorization
|
// Пробуем получить токен из заголовка Authorization
|
||||||
authHeader := r.Header.Get("Authorization")
|
authHeader := r.Header.Get("Authorization")
|
||||||
@@ -88,6 +89,8 @@ func AuthMiddleware(jwtService service.JWTService, userRepo repository.UserRepos
|
|||||||
zap.Any("user_id", userID),
|
zap.Any("user_id", userID),
|
||||||
zap.String("username", user.FirstName))
|
zap.String("username", user.FirstName))
|
||||||
|
|
||||||
|
|
||||||
|
logger.Debug("authMiddleware End")
|
||||||
next.ServeHTTP(w, r.WithContext(ctx))
|
next.ServeHTTP(w, r.WithContext(ctx))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -98,7 +101,7 @@ 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("RequireAuth method start")
|
||||||
logger.Debug("Extracted user ID from token",
|
logger.Debug("Extracted user ID from token",
|
||||||
zap.Any("user_id", userID))
|
zap.Any("user_id", userID))
|
||||||
|
|
||||||
@@ -109,6 +112,7 @@ func RequireAuth(next http.Handler) http.Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logger.Debug("User authenticated", zap.Any("user_id", userID))
|
logger.Debug("User authenticated", zap.Any("user_id", userID))
|
||||||
|
logger.Debug("authMiddleware End")
|
||||||
next.ServeHTTP(w, r)
|
next.ServeHTTP(w, r)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user