Added validation and fixed errors
This commit is contained in:
		
							
								
								
									
										19
									
								
								SchengenVisaApi/Infrastructure/Common/UserIdProvider.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								SchengenVisaApi/Infrastructure/Common/UserIdProvider.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| using System.Security.Claims; | ||||
| using ApplicationLayer.InfrastructureServicesInterfaces; | ||||
| using Microsoft.AspNetCore.Http; | ||||
|  | ||||
| namespace Infrastructure.Common | ||||
| { | ||||
|     public class UserIdProvider(IHttpContextAccessor contextAccessor) : IUserIdProvider | ||||
|     { | ||||
|         Guid IUserIdProvider.GetUserId() | ||||
|         { | ||||
|             var claim = contextAccessor.HttpContext!.User.Claims.SingleOrDefault(claim => claim.Type == ClaimTypes.NameIdentifier); | ||||
|             if (claim is null) | ||||
|             { | ||||
|                 throw new InvalidOperationException("UserIdProvider call for request with no authorization"); | ||||
|             } | ||||
|             return Guid.Parse(claim.Value); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user