Handle not found user profile gracefully

Changes from throwing an exception when a user profile is not found to returning null.

This prevents the application from crashing when a user profile is not found, allowing for more graceful error handling.
This commit is contained in:
martinshoob 2025-08-11 18:46:35 +02:00
parent 7bf7f23925
commit 1dc37d3282

View file

@ -13,7 +13,7 @@ public class ApplicationUserService(ApplicationDbContext context)
{
var appUserId = identity.FindFirst(ClaimTypes.NameIdentifier)?.Value;
var profile = await _context.UserProfiles
.FirstAsync(x => x.ApplicationUserId.ToString() == appUserId)
.FirstOrDefaultAsync(x => x.ApplicationUserId.ToString() == appUserId)
?? throw new NotFoundException();
return profile;