[frontend] Fix build warnings
This commit is contained in:
parent
98ac934897
commit
bc14abbacc
4 changed files with 26 additions and 17 deletions
|
@ -3,7 +3,7 @@ using Iceshrimp.Shared.Schemas;
|
|||
|
||||
namespace Iceshrimp.Frontend.Core.Schemas;
|
||||
|
||||
public class StoredUser() : UserResponse
|
||||
public class StoredUser : UserResponse
|
||||
{
|
||||
[JsonPropertyName("token")] public required string Token { get; set; }
|
||||
[JsonPropertyName("token")] public required string Token { get; set; }
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
using Blazored.LocalStorage;
|
||||
using Iceshrimp.Frontend.Core.Schemas;
|
||||
using Iceshrimp.Shared.Schemas;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace Iceshrimp.Frontend.Core.Services;
|
||||
|
@ -50,7 +49,7 @@ internal class SessionService
|
|||
WriteUsers();
|
||||
}
|
||||
|
||||
private StoredUser? GetUserById(string id)
|
||||
private StoredUser GetUserById(string id)
|
||||
{
|
||||
var user = Users[id];
|
||||
return user;
|
||||
|
|
|
@ -3,15 +3,15 @@
|
|||
@using Iceshrimp.Frontend.Core.Schemas
|
||||
@using Iceshrimp.Frontend.Core.Services
|
||||
@using Iceshrimp.Shared.Schemas
|
||||
@inject ApiService Api
|
||||
@inject SessionService SessionService
|
||||
@inject ApiService Api
|
||||
@inject SessionService SessionService
|
||||
@inject NavigationManager Navigation
|
||||
<h3>Login</h3>
|
||||
<div>
|
||||
<input
|
||||
@bind="@Username" />
|
||||
@bind="@Username"/>
|
||||
<input
|
||||
@bind="@Password" />
|
||||
@bind="@Password"/>
|
||||
<button @onclick="Submit" disabled="@Loading">Login</button>
|
||||
</div>
|
||||
@if (Loading)
|
||||
|
@ -36,6 +36,14 @@
|
|||
Loading = true;
|
||||
try
|
||||
{
|
||||
if (Username == null || Password == null)
|
||||
{
|
||||
Loading = false;
|
||||
Failure = true;
|
||||
StateHasChanged(); // Manually triggering a state update, else component will not re-render.
|
||||
return;
|
||||
}
|
||||
|
||||
var res = await Api.Auth.Login(new AuthRequest { Username = Username, Password = Password });
|
||||
switch (res.Status)
|
||||
{
|
||||
|
@ -70,4 +78,5 @@
|
|||
StateHasChanged(); // Manually triggering a state update, else component will not re-render.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -3,31 +3,31 @@
|
|||
@using Iceshrimp.Frontend.Core.Services
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
@using Microsoft.AspNetCore.Components.Authorization
|
||||
@inject SessionService Session
|
||||
@inject SessionService Session
|
||||
@inject NavigationManager Navigation
|
||||
<h3>Timeline</h3>
|
||||
@if (username != null)
|
||||
@if (_username != null)
|
||||
{
|
||||
<span>You are logged in as @username </span>
|
||||
<span>You are logged in as @_username </span>
|
||||
<AuthorizeView>
|
||||
<p>Authorization says you are @context.User.Identity!.Name</p>
|
||||
</AuthorizeView>
|
||||
<button @onclick="Logout">Logout</button>
|
||||
}else
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>Not logged in</span>
|
||||
}
|
||||
|
||||
|
||||
|
||||
@code {
|
||||
private string? username;
|
||||
private string? _username;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
if (Session.Current != null)
|
||||
{
|
||||
username = Session.Current.Username;
|
||||
_username = Session.Current.Username;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,4 +36,5 @@
|
|||
Session.EndSession();
|
||||
Navigation.NavigateTo("/login");
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue