เก็บ log User บุคคลภายนอก

This commit is contained in:
harid 2025-12-17 16:11:16 +07:00
parent 0043097b2d
commit dfa9dd3b47

View file

@ -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 ?? ""
};