forked from AcaMate/AcaMate_Web
[✨] 로그인 후 레이아웃 변경
This commit is contained in:
parent
9621169d57
commit
05e8fcd0b0
|
@ -41,15 +41,23 @@ public class StorageService
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task RemoveItemAsync(string key, STORAGE_TYPE type = STORAGE_TYPE.Session)
|
public async Task<bool> RemoveItemAsync(string key, STORAGE_TYPE type = STORAGE_TYPE.Session)
|
||||||
{
|
{
|
||||||
await (type switch
|
try
|
||||||
{
|
{
|
||||||
STORAGE_TYPE.Cookie => _js.InvokeVoidAsync("deleteCookie", key),
|
await (type switch
|
||||||
STORAGE_TYPE.Local => _js.InvokeVoidAsync("localStorage.removeItem", key),
|
{
|
||||||
STORAGE_TYPE.Session => _js.InvokeVoidAsync("sessionStorage.removeItem", key),
|
STORAGE_TYPE.Cookie => _js.InvokeVoidAsync("deleteCookie", key),
|
||||||
_ => throw new ArgumentException("Invalid storage type")
|
STORAGE_TYPE.Local => _js.InvokeVoidAsync("localStorage.removeItem", key),
|
||||||
});
|
STORAGE_TYPE.Session => _js.InvokeVoidAsync("sessionStorage.removeItem", key),
|
||||||
|
_ => throw new ArgumentException("Invalid storage type")
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,15 @@
|
||||||
<span class="truncate">시작하기</span>
|
<span class="truncate">시작하기</span>
|
||||||
</button>
|
</button>
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<button class="flex items-center justify-center w-10 h-10 rounded-full text-white text-sm font-bold leading-normal tracking-[0.015em] mr-4"
|
||||||
|
@onclick="OnClickLogout">
|
||||||
|
<div class="relative w-8 h-8">
|
||||||
|
<img src="Resources/Images/Icon/Logout.png" alt="로그아웃" class="w-6 h-6 absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 hover:brightness-0 hover:saturate-100 hover:invert hover:sepia hover:hue-rotate-[180deg] hover:brightness-[0.7] hover:contrast-[0.8] transition-all duration-200" />
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -45,6 +54,13 @@
|
||||||
<span class="truncate">시작하기</span>
|
<span class="truncate">시작하기</span>
|
||||||
</button>
|
</button>
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<button class="flex w-full cursor-pointer items-center justify-center rounded-lg h-10 px-4 bg-second-normal hover:bg-second-dark text-white text-sm font-bold leading-normal tracking-[0.015em]"
|
||||||
|
@onclick="OnClickLogout">
|
||||||
|
<span class="truncate">로그아웃</span>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,11 +24,12 @@ public partial class TopProjectNav : ComponentBase
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
Console.WriteLine("TopNAV 확인");
|
Console.WriteLine("TopNAV 확인");
|
||||||
isLogin = isLogin = bool.TryParse(await StorageService.GetItemAsync("IsLogin"), out var result) && result;
|
isLogin = bool.TryParse(await StorageService.GetItemAsync("IsLogin"), out var result) && result;
|
||||||
if (isLogin) return;
|
// if (!isLogin && !string.IsNullOrEmpty(UserName)) return;
|
||||||
|
if (!isLogin) return; // && !string.IsNullOrEmpty(UserName)) return;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
var encryptedName = await StorageService.GetItemAsync("USER");
|
var encryptedName = await StorageService.GetItemAsync("USER");
|
||||||
Console.WriteLine($"{encryptedName}");
|
Console.WriteLine($"{encryptedName}");
|
||||||
if (!string.IsNullOrEmpty(encryptedName))
|
if (!string.IsNullOrEmpty(encryptedName))
|
||||||
|
@ -103,6 +104,14 @@ public partial class TopProjectNav : ComponentBase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
if (isLogin) {
|
||||||
|
isLogin = false;
|
||||||
|
await StorageService.SetItemAsync("IsLogin","false");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Console.WriteLine("로그인되지 않은 상태");
|
Console.WriteLine("로그인되지 않은 상태");
|
||||||
|
@ -136,4 +145,19 @@ public partial class TopProjectNav : ComponentBase
|
||||||
if (isOpen) isOpen = !isOpen;
|
if (isOpen) isOpen = !isOpen;
|
||||||
NavigationManager.NavigateTo("/auth");
|
NavigationManager.NavigateTo("/auth");
|
||||||
}
|
}
|
||||||
|
public async Task OnClickLogout()
|
||||||
|
{
|
||||||
|
// var isRemoved = await StorageService.RemoveItemAsync("USER");
|
||||||
|
if (await StorageService.RemoveItemAsync("IsLogin")) {
|
||||||
|
isLogin = false;
|
||||||
|
if (await StorageService.RemoveItemAsync("USER")) {
|
||||||
|
UserName = null;
|
||||||
|
Console.WriteLine("LOGOUT");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("로그아웃 처리 중 오류가 발생했습니다.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
BIN
wwwroot/Resources/Images/Icon/Logout.png
Normal file
BIN
wwwroot/Resources/Images/Icon/Logout.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 636 B |
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user