From dfa9dd3b47192cd91367cd988d6c861ea5537963 Mon Sep 17 00:00:00 2001 From: harid Date: Wed, 17 Dec 2025 16:11:16 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=81=E0=B9=87=E0=B8=9A=20log=20Us?= =?UTF-8?q?er=20=E0=B8=9A=E0=B8=B8=E0=B8=84=E0=B8=84=E0=B8=A5=E0=B8=A0?= =?UTF-8?q?=E0=B8=B2=E0=B8=A2=E0=B8=99=E0=B8=AD=E0=B8=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/RequestLoggingMiddleware.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Core/RequestLoggingMiddleware.cs b/Core/RequestLoggingMiddleware.cs index 64a2741..7d24362 100644 --- a/Core/RequestLoggingMiddleware.cs +++ b/Core/RequestLoggingMiddleware.cs @@ -160,6 +160,13 @@ namespace BMA.EHR.Recurit.Exam.Service.Core var token = context.Request.Headers["Authorization"]; var pf = await GetProfileByKeycloakIdAsync(Guid.Parse(keycloakId), token); + var _userFullname = string.Empty; + var _userName = string.Empty; + if (keycloakId != "00000000-0000-0000-0000-000000000000" && pf == null) + { + _userFullname = context.User?.FindFirst("name")?.Value; + _userName = context.User?.FindFirst("preferred_username")?.Value; + } await _next(context); // ดำเนินการต่อไปยัง Middleware อื่น ๆ @@ -260,8 +267,8 @@ namespace BMA.EHR.Recurit.Exam.Service.Core output = responseBodyJson, userId = keycloakId, - userName = $"{pf?.Prefix ?? ""}{pf?.FirstName ?? ""} {pf?.LastName ?? ""}", - user = pf?.CitizenId ?? "" + userName = pf != null ? $"{pf?.Prefix ?? ""}{pf?.FirstName ?? ""} {pf?.LastName ?? ""}" : _userFullname ?? "", + user = pf != null ? pf?.CitizenId ?? "" : _userName ?? "" };