* Changed views to have them in the same layout

* Added Authorization
This commit is contained in:
2025-02-28 13:33:01 +01:00
parent aedb5810c2
commit b8fbb789ad
35 changed files with 1605 additions and 1306 deletions

View File

@@ -10,18 +10,20 @@ public class CustomAuthenticationStateProvider(ILocalStorageService localStorage
private string? _token;
private ClaimsPrincipal _currentUser = new(new ClaimsIdentity());
public override Task<AuthenticationState> GetAuthenticationStateAsync()
public override async Task<AuthenticationState> GetAuthenticationStateAsync()
{
_token = await localStorage.GetItemAsync<string>("authToken");
if (string.IsNullOrEmpty(_token))
{
return Task.FromResult(new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity())));
return await Task.FromResult(new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity())));
}
var handler = new JwtSecurityTokenHandler();
var jwtToken = handler.ReadJwtToken(_token);
var identity = new ClaimsIdentity(jwtToken.Claims, "jwt");
var identity = new ClaimsIdentity(jwtToken.Claims, "jwt", JwtRegisteredClaimNames.Sub, null);
_currentUser = new ClaimsPrincipal(identity);
return Task.FromResult(new AuthenticationState(_currentUser));
return await Task.FromResult(new AuthenticationState(_currentUser));
}
public async Task MarkUserAsAuthenticated(string? token)
@@ -30,7 +32,7 @@ public class CustomAuthenticationStateProvider(ILocalStorageService localStorage
await localStorage.SetItemAsync("authToken", token);
var handler = new JwtSecurityTokenHandler();
var jwtToken = handler.ReadJwtToken(token);
var identity = new ClaimsIdentity(jwtToken.Claims, "jwt");
var identity = new ClaimsIdentity(jwtToken.Claims, "jwt", JwtRegisteredClaimNames.Sub, null);
_currentUser = new ClaimsPrincipal(identity);
NotifyAuthenticationStateChanged(Task.FromResult(new AuthenticationState(_currentUser)));
}
@@ -42,21 +44,8 @@ public class CustomAuthenticationStateProvider(ILocalStorageService localStorage
_currentUser = new ClaimsPrincipal(new ClaimsIdentity());
NotifyAuthenticationStateChanged(Task.FromResult(new AuthenticationState(_currentUser)));
}
public async Task InitializeAsync()
{
_token = await localStorage.GetItemAsync<string>("authToken");
if (!string.IsNullOrEmpty(_token))
{
var handler = new JwtSecurityTokenHandler();
var jwtToken = handler.ReadJwtToken(_token);
var identity = new ClaimsIdentity(jwtToken.Claims, "jwt");
_currentUser = new ClaimsPrincipal(identity);
NotifyAuthenticationStateChanged(Task.FromResult(new AuthenticationState(_currentUser)));
}
}
public string? GetToken() => _token;
public ClaimsPrincipal GetCurrentUser() => _currentUser;
}