Skip to content

Commit db1d999

Browse files
authored
Avoid exception when attempting to find member by Id when Id is not an expected Guid or integer, as can be the case with external member providers. (#18320)
1 parent 18047a7 commit db1d999

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/Umbraco.Infrastructure/Security/MemberUserStore.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,20 @@ public override Task<IdentityResult> DeleteAsync(
321321
throw new ArgumentNullException(nameof(userId));
322322
}
323323

324-
IMember? user = Guid.TryParse(userId, out Guid key)
325-
? _memberService.GetByKey(key)
326-
: _memberService.GetById(UserIdToInt(userId));
324+
// With external member providers we can get a ID here that's not a GUID or integer.
325+
// We can't retrieve the member, but if that's the case we shouldn't throw an exception,
326+
// just return null in the same way as when the member isn't found.
327+
// See: https://github.com/umbraco/Umbraco-CMS/issues/14713
328+
IMember? user = null;
329+
if (Guid.TryParse(userId, out Guid key))
330+
{
331+
user = _memberService.GetByKey(key);
332+
}
333+
else if (TryUserIdToInt(userId, out int id))
334+
{
335+
user = _memberService.GetById(id);
336+
}
337+
327338
if (user == null)
328339
{
329340
return Task.FromResult((MemberIdentityUser)null!)!;

0 commit comments

Comments
 (0)