Implemented Login workflow
This commit is contained in:
27
SpotiParty.Web/Components/Pages/CallbackPage.razor
Normal file
27
SpotiParty.Web/Components/Pages/CallbackPage.razor
Normal file
@@ -0,0 +1,27 @@
|
||||
@page "/callback"
|
||||
@using SpotiParty.Web.Services
|
||||
@inject NavigationManager Navigator
|
||||
@inject AuthorizationHandler AuthHandler
|
||||
|
||||
@code {
|
||||
[Parameter, SupplyParameterFromQuery(Name = "error")]
|
||||
public string? Error { get; set; }
|
||||
|
||||
[Parameter, SupplyParameterFromQuery(Name = "code")]
|
||||
public string? Code { get; set; }
|
||||
|
||||
[Parameter, SupplyParameterFromQuery(Name = "state")]
|
||||
public string? State { get; set; }
|
||||
|
||||
protected override async Task OnInitializedAsync() {
|
||||
await base.OnInitializedAsync();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(Code)) {
|
||||
Navigator.NavigateTo("/login", forceLoad: true);
|
||||
return;
|
||||
}
|
||||
|
||||
await AuthHandler.HandleCallback(Code);
|
||||
Navigator.NavigateTo("/enqueue", forceLoad: true);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
@page "/enqueue"
|
||||
@page "/enqueue/{userid}"
|
||||
@using SpotiParty.Web.Components.Components
|
||||
@rendermode InteractiveServer
|
||||
|
||||
|
||||
@@ -4,7 +4,11 @@ using SpotiParty.Web.Services;
|
||||
|
||||
namespace SpotiParty.Web.Components.Pages;
|
||||
|
||||
public partial class EnqueuePage(AuthorizationHandler authHandler) : ComponentBase {
|
||||
public partial class EnqueuePage(AuthorizationHandler authHandler, NavigationManager navigator) : ComponentBase {
|
||||
|
||||
[Parameter]
|
||||
public string UserId { get; set; } = string.Empty;
|
||||
|
||||
private readonly int _currentYear = DateTime.Now.Year;
|
||||
private SpotifyClient _client = null!;
|
||||
|
||||
@@ -17,7 +21,20 @@ public partial class EnqueuePage(AuthorizationHandler authHandler) : ComponentBa
|
||||
|
||||
protected override async Task OnInitializedAsync() {
|
||||
await base.OnInitializedAsync();
|
||||
_client = await authHandler.ConfigureClient();
|
||||
|
||||
if (!Guid.TryParse(UserId, out var guid)) {
|
||||
navigator.NavigateTo("/", forceLoad: true);
|
||||
return;
|
||||
}
|
||||
|
||||
var client = await authHandler.ConfigureClient(guid);
|
||||
|
||||
if (client is null) {
|
||||
navigator.NavigateTo("/", forceLoad: true);
|
||||
return;
|
||||
}
|
||||
|
||||
_client = client;
|
||||
}
|
||||
|
||||
private async Task ExecuteSearch() {
|
||||
@@ -51,9 +68,8 @@ public partial class EnqueuePage(AuthorizationHandler authHandler) : ComponentBa
|
||||
private async Task DialogAccept() {
|
||||
if (_selectedTrack is null || _isAdding) return;
|
||||
_isAdding = true;
|
||||
/*var request = new PlayerAddToQueueRequest(_selectedTrack.Uri);
|
||||
await _client.Player.AddToQueue(request);*/
|
||||
await Task.Delay(3000); //TODO: Simulate adding
|
||||
var request = new PlayerAddToQueueRequest(_selectedTrack.Uri);
|
||||
await _client.Player.AddToQueue(request);
|
||||
_isAdding = false;
|
||||
|
||||
_success = true;
|
||||
|
||||
@@ -105,16 +105,3 @@ footer {
|
||||
background: var(--color-background-light) !important;
|
||||
}
|
||||
|
||||
.button-secondary {
|
||||
padding: 0.6rem 1rem;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
background: var(--color-accent);
|
||||
color: var(--color-text);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.button-secondary:hover {
|
||||
background: #555555;
|
||||
}
|
||||
|
||||
|
||||
17
SpotiParty.Web/Components/Pages/LoginPage.razor
Normal file
17
SpotiParty.Web/Components/Pages/LoginPage.razor
Normal file
@@ -0,0 +1,17 @@
|
||||
@page "/login"
|
||||
@using SpotiParty.Web.Services
|
||||
|
||||
<a class="button-primary" href="@_uri">Mit Spotify einloggen</a>
|
||||
|
||||
@inject AuthorizationHandler AuthHandler
|
||||
|
||||
@code {
|
||||
|
||||
private Uri _uri = null!;
|
||||
|
||||
protected override async Task OnInitializedAsync() {
|
||||
await base.OnInitializedAsync();
|
||||
_uri = await AuthHandler.ConstructLoginUri();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
protected override void OnInitialized() {
|
||||
base.OnInitialized();
|
||||
Navigator.NavigateTo("/enqueue", forceLoad: true);
|
||||
Navigator.NavigateTo("/login", forceLoad: true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user