Created
July 10, 2023 12:45
-
-
Save davepermen/bbce76e1063ba72ac2b85bfa8dd25bfa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using Conesoft.Files | |
<AuthorizeView> | |
<Authorized> | |
<ul> | |
@foreach (var token in Tokens) | |
{ | |
<li> | |
<b>@token</b> | |
<button @onclick="() => DeleteToken(token)">x</button> | |
</li> | |
} | |
</ul> | |
</Authorized> | |
</AuthorizeView> | |
@code { | |
[CascadingParameter] | |
private Task<AuthenticationState>? authenticationState { get; set; } | |
private Conesoft.Files.Directory tokenRoot = Conesoft.Files.Directory.From(@"C:\Temp\users\tokens"); | |
private string[] Tokens = Array.Empty<string>(); | |
protected override async Task OnInitializedAsync() | |
{ | |
await authenticationState.Authorized(user => | |
{ | |
var _ = (tokenRoot / user).WatchLive(async files => | |
{ | |
await InvokeAsync(() => | |
{ | |
Tokens = files.All.Select(f => f.Name).ToArray(); | |
StateHasChanged(); | |
}); | |
}); | |
}); | |
} | |
async Task DeleteToken(string token) | |
{ | |
await authenticationState.Authorized(user => | |
{ | |
var file = tokenRoot / user / Filename.FromExtended(token); | |
file.Delete(); | |
StateHasChanged(); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment