forked from AcaMate/AcaMate_Web
1. 쿠키만 사용하던 저장 동작을 다른 저장소도 사용하게 변경 1.1. 쿠키 대신 세션 레포지토리를 기본적으로 사용하게 Service 코드 구현 2. 로그인 되었을 경우 화면 표기 변경 2.1. 시작하기 버튼 hidden 처리 2.2. 사용자 이름 불러오기 2.3. 로그인 동작 관련 변수 스토리지 저장 2.4. 서버에서 직접적인 크라이언트 쿠키 저장이 아닌 서버는 뒤의 값으로 간섭하게 변경
74 lines
2.6 KiB
C#
74 lines
2.6 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Routing;
|
|
|
|
using Front.Program.Views.Project;
|
|
using Front.Program.Services;
|
|
|
|
namespace Front.Program.Layout;
|
|
|
|
public partial class MainLayout : LayoutComponentBase, IDisposable
|
|
{
|
|
[Inject]
|
|
NavigationManager Navigation { get; set; } = default!;
|
|
|
|
[Inject]
|
|
LoadingService LoadingService { get; set; } = default!;
|
|
|
|
[Inject]
|
|
StorageService StorageService { get; set; } = default!;
|
|
|
|
// 경로의 시작 부분
|
|
// protected bool isHidePrjTop => Navigation.ToBaseRelativePath(Navigation.Uri).StartsWith("auth", StringComparison.OrdinalIgnoreCase);
|
|
|
|
// 경로의 끝 부분
|
|
protected bool isHidePrjTop => Navigation.ToBaseRelativePath(Navigation.Uri).EndsWith("auth", StringComparison.OrdinalIgnoreCase);
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
LoadingService.OnChange += StateHasChanged;
|
|
Navigation.LocationChanged += HandleLocationChanged;
|
|
HandleLocationChanged(this, new LocationChangedEventArgs(Navigation.Uri, false));
|
|
}
|
|
|
|
private async void HandleLocationChanged(object? sender, LocationChangedEventArgs e)
|
|
{
|
|
LoadingService.HideNavigationLoading();
|
|
|
|
var uri = Navigation.ToAbsoluteUri(Navigation.Uri);
|
|
Console.WriteLine($"리다이렉트된 URI: {uri}");
|
|
|
|
if (uri.Query.Contains("auth="))
|
|
{
|
|
var query = uri.Query.TrimStart('?');
|
|
var parameters = query.Split('&')
|
|
.Select(p => p.Split('='))
|
|
.Where(p => p.Length == 2)
|
|
.ToDictionary(p => p[0], p => p[1]);
|
|
|
|
if (parameters.TryGetValue("auth", out var auth))
|
|
{
|
|
Console.WriteLine($"auth 파라미터 값: {auth}");
|
|
if (auth == "true")
|
|
{
|
|
await StorageService.SetItemAsync("IsLogin", "true");
|
|
Console.WriteLine("로그인 상태를 true로 설정했습니다.");
|
|
}
|
|
else
|
|
{
|
|
await StorageService.RemoveItemAsync("IsLogin");
|
|
Console.WriteLine("로그인 상태를 제거했습니다.");
|
|
}
|
|
|
|
// 파라미터를 제거하고 리다이렉트
|
|
var baseUri = uri.GetLeftPart(UriPartial.Path);
|
|
Navigation.NavigateTo(baseUri, forceLoad: false);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
LoadingService.OnChange -= StateHasChanged;
|
|
Navigation.LocationChanged -= HandleLocationChanged;
|
|
}
|
|
} |