fix: fixed auth issues

Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
limited_dev 2023-06-12 18:51:25 +02:00
parent 766e6054dc
commit 6630b4963e
11 changed files with 308 additions and 243 deletions

View file

@ -8,14 +8,14 @@ namespace ImageBoardServerApp.Auth;
public class CustomAuthenticationStateProvider : AuthenticationStateProvider
{
private readonly ProtectedLocalStorage _sessionStorage;
private ClaimsPrincipal _anonymous = new ClaimsPrincipal(new ClaimsIdentity());
public CustomAuthenticationStateProvider(ProtectedLocalStorage sessionStorage)
{
_sessionStorage = sessionStorage;
}
public override async Task<AuthenticationState> GetAuthenticationStateAsync()
{
try
@ -30,11 +30,12 @@ public class CustomAuthenticationStateProvider : AuthenticationStateProvider
new Claim(ClaimTypes.Name, userSession.UserID.ToString()),
new Claim(ClaimTypes.Role, userSession.Role)
}, "CustomAuth"));
return await Task.FromResult(new AuthenticationState(claimsPrincipal));
return new AuthenticationState(claimsPrincipal);
}
catch
{
return await Task.FromResult(new AuthenticationState(_anonymous));
Console.WriteLine("Returned Anon Auth due to err");
return new AuthenticationState(_anonymous);
}
}
@ -56,7 +57,7 @@ public class CustomAuthenticationStateProvider : AuthenticationStateProvider
await _sessionStorage.DeleteAsync("UserSession");
claimsPrincipal = _anonymous;
}
NotifyAuthenticationStateChanged(Task.FromResult(new AuthenticationState(claimsPrincipal)));
}
}