Skip to content

Commit

Permalink
VCST-192: Anonymous Cart Reset Issue Upon Browser Refresh (#72)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
OlegoO authored Feb 15, 2024
1 parent 103becd commit 3e2194e
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using GraphQL;
using GraphQL.Builders;
Expand Down Expand Up @@ -67,7 +68,8 @@ public void Build(ISchema schema)
Type = GraphTypeExtenstionHelper.GetActualType<UserType>(),
Resolver = new AsyncFieldResolver<object>(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
Expand All @@ -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;
})
});

Expand Down

0 comments on commit 3e2194e

Please sign in to comment.