1. 로그인 동작을 위해서 viewmodel 로 관련 뷰에서 동작할 모든 로직을 viewmodel에서 관리 1.1. view 와 viewmodel의 관계는 1:N으로 동작하는것을 기반으로 두고 있음 2. API 접근하는 방식도 웹만의 접근 방법에서 수정 3. 로그인 동작 정보 받는 로직 수정
77 lines
2.5 KiB
C#
77 lines
2.5 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Routing;
|
|
|
|
using Front.Program.ViewModels;
|
|
using Front.Program.Services;
|
|
|
|
namespace Front.Program.Views.Project;
|
|
|
|
public partial class About : ComponentBase, IDisposable
|
|
{
|
|
[Inject]
|
|
NavigationManager Navigation { get; set; } = default!;
|
|
|
|
[Inject]
|
|
StorageService StorageService { get; set; } = default!;
|
|
|
|
[Inject]
|
|
QueryParamService QueryParamService { get; set; } = default!;
|
|
|
|
[Inject] UserViewModel UserViewModel { get; set; } = default!;
|
|
|
|
private bool _isProcessing = false;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
Navigation.LocationChanged += HandleLocationChanged;
|
|
HandleLocationChanged(this, new LocationChangedEventArgs(Navigation.Uri, false));
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Navigation.LocationChanged -= HandleLocationChanged;
|
|
}
|
|
|
|
private async Task OnClickEvent()
|
|
{
|
|
// NavigationManager.NavigateTo("/redirectpage");
|
|
Console.WriteLine("Redirecting to redirect page");
|
|
}
|
|
|
|
private async void HandleLocationChanged(object? sender, LocationChangedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
// 다중 실행 방지
|
|
if (_isProcessing) return;
|
|
_isProcessing = true;
|
|
|
|
var uri = Navigation.ToAbsoluteUri(Navigation.Uri);
|
|
Console.WriteLine($"리다이렉트된 URI: {uri}");
|
|
|
|
// 쿼리 파라미터가 있는 경우에만 처리
|
|
if (!string.IsNullOrEmpty(uri.Query))
|
|
{
|
|
var queryParam = QueryParamService.ParseQueryParam(uri);
|
|
await QueryParamService.AuthCheck(queryParam, StorageService);
|
|
|
|
// 유저 정보 확인하는거 (로그인 했으니 값 가져와야지)
|
|
await UserViewModel.GetUserDataAsync();
|
|
|
|
// 쿼리 파라미터를 제거한 기본 URI로 리다이렉트
|
|
var baseUri = uri.GetLeftPart(UriPartial.Path);
|
|
Console.WriteLine($"리다이렉트할 URI: {baseUri}");
|
|
await InvokeAsync(StateHasChanged); // StateHasChanged를 호출하여 UI 업데이트
|
|
Navigation.NavigateTo(baseUri, forceLoad: false);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"Error in HandleLocationChanged: {ex.Message}");
|
|
}
|
|
finally
|
|
{
|
|
_isProcessing = false;
|
|
}
|
|
}
|
|
} |