Добавил определение пользователя

This commit is contained in:
2026-06-17 02:59:06 +03:00
parent d659a0289f
commit da47d7fdf3
@@ -4,6 +4,7 @@ using URL_Shortener.DTO;
using URL_Shortener.Models;
using HashidsNet;
using Microsoft.AspNetCore.Authorization;
using System.Security.Claims;
namespace URL_Shortener.Controllers
{
@@ -86,7 +87,9 @@ namespace URL_Shortener.Controllers
if (shortUrl == null)
return NotFound();
// TODO: определение пользователя по jwt
if (!int.TryParse(User.FindFirstValue(ClaimTypes.NameIdentifier), out var userId) ||
shortUrl.UserId != userId)
throw new Exception("Not authorized");
_db.ShortUrls.Remove(shortUrl);