From 3e2194e68a193303ac502b31c69cca9060c40f30 Mon Sep 17 00:00:00 2001 From: Oleg Zhuk Date: Thu, 15 Feb 2024 13:55:19 +0200 Subject: [PATCH] VCST-192: Anonymous Cart Reset Issue Upon Browser Refresh (#72) fix: An issue was identified where the anonymous cart was being reset upon browser refresh. Virto Storefront, Virto Commerce Experience and Profile Experience module should be updated as well. --- .../Schemas/ProfileSchema.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/VirtoCommerce.ProfileExperienceApiModule.Data/Schemas/ProfileSchema.cs b/src/VirtoCommerce.ProfileExperienceApiModule.Data/Schemas/ProfileSchema.cs index 1661e2f6..63c459b5 100644 --- a/src/VirtoCommerce.ProfileExperienceApiModule.Data/Schemas/ProfileSchema.cs +++ b/src/VirtoCommerce.ProfileExperienceApiModule.Data/Schemas/ProfileSchema.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Security.Claims; using System.Threading.Tasks; using GraphQL; using GraphQL.Builders; @@ -67,7 +68,8 @@ public void Build(ISchema schema) Type = GraphTypeExtenstionHelper.GetActualType(), Resolver = new AsyncFieldResolver(async context => { - var userName = ((GraphQLUserContext)context.UserContext).User?.Identity?.Name; + var principal = context.GetCurrentPrincipal(); + var userName = principal?.Identity?.Name; if (!string.IsNullOrEmpty(userName)) { var result = await _mediator.Send(new GetUserQuery @@ -76,7 +78,16 @@ public void Build(ISchema schema) }); return result; } - return AnonymousUser.Instance; + + var anonymousUser = AnonymousUser.Instance; + + var userId = principal?.FindFirstValue(ClaimTypes.NameIdentifier); + if (!string.IsNullOrEmpty(userId)) + { + anonymousUser.Id = userId; + } + + return anonymousUser; }) });