Skip to content

Commit

Permalink
VCST-1762: Add 'userId' argument to 'me' query (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-dudarev authored Sep 9, 2024
1 parent 97250fe commit 36ba5d5
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public void Build(ISchema schema)
schema.Query.AddField(new FieldType
{
Name = "me",
Arguments = new QueryArguments(new QueryArgument<StringGraphType> { Name = "userId" }),
Type = GraphTypeExtenstionHelper.GetActualType<UserType>(),
Resolver = new AsyncFieldResolver<object>(async context =>
{
Expand All @@ -82,8 +83,10 @@ public void Build(ISchema schema)

var anonymousUser = AnonymousUser.Instance;

var userId = principal?.FindFirstValue(ClaimTypes.NameIdentifier);
if (!string.IsNullOrEmpty(userId))
var userId = principal?.FindFirstValue(ClaimTypes.NameIdentifier) ??
context.GetArgument<string>("userId");

if (!string.IsNullOrEmpty(userId) && !await UserExistsAsync(userId))
{
anonymousUser.Id = userId;
}
Expand Down Expand Up @@ -832,5 +835,13 @@ private async Task<string> GetUserEmailAsync(string userId)

return user?.Email;
}

private async Task<bool> UserExistsAsync(string userId)
{
var signInManager = _signInManagerFactory();
var user = await signInManager.UserManager.FindByIdAsync(userId);

return user != null;
}
}
}

0 comments on commit 36ba5d5

Please sign in to comment.