Authorize API
All checks were successful
Game Ideas build for PR / build_blazor_app (pull_request) Successful in 40s

This commit is contained in:
2025-04-21 01:52:01 +02:00
parent 7aedbff784
commit b3212c5e0d
13 changed files with 130 additions and 74 deletions

View File

@@ -1,12 +1,26 @@
using GameIdeas.Shared.Dto;
using Microsoft.AspNetCore.Components.Authorization;
using System.Security.Claims;
namespace GameIdeas.BlazorApp.Helpers;
public static class GameHelper
{
public static void WriteTrackingDto(GameDetailDto game)
public static void WriteTrackingDto(GameDetailDto game, AuthenticationState authState)
{
game.CreationUserId = 100000;
if (authState == null)
{
throw new ArgumentNullException(nameof(authState), "Authentication state missing");
}
var userId = authState.User.FindFirstValue(ClaimTypes.Sid);
if (userId == null)
{
throw new ArgumentNullException(nameof(authState), "user state missing");
}
game.CreationUserId = userId;
game.CreationDate = DateTime.Now;
}