added basic functionalities (login, create/del/rename pages)

This commit is contained in:
taywon18
2024-09-22 11:48:59 +02:00
parent d531454166
commit 5707f5a2d4
12 changed files with 374 additions and 31 deletions

View File

@@ -0,0 +1,38 @@
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage;
using System.Security.Claims;
namespace Tagger.Service;
public class CustomAuthStateProvider : AuthenticationStateProvider
{
private readonly ProtectedSessionStorage SessionStorage;
private ClaimsPrincipal Anonymous = new(new ClaimsIdentity());
public CustomAuthStateProvider(ProtectedSessionStorage sessionStorage)
{
SessionStorage = sessionStorage;
}
public override async Task<AuthenticationState> GetAuthenticationStateAsync()
{
var userSessionStorageResult = await SessionStorage.GetAsync<User>(nameof(User));
if(!userSessionStorageResult.Success || userSessionStorageResult.Value is null)
return new AuthenticationState(Anonymous);
var claimPrincipal = new ClaimsPrincipal(new ClaimsIdentity(new List<Claim>
{
new Claim(ClaimTypes.Name, userSessionStorageResult.Value.Name)
}));
return new(claimPrincipal);
}
public async Task SetSession(User? user)
{
if(user is null)
await SessionStorage.DeleteAsync(nameof(User));
else
await SessionStorage.SetAsync(nameof(User), user);
}
}