Authorize API
All checks were successful
Game Ideas build for PR / build_blazor_app (pull_request) Successful in 40s
All checks were successful
Game Ideas build for PR / build_blazor_app (pull_request) Successful in 40s
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user