[] 로그인 후 레이아웃 변경

This commit is contained in:
SEAN-59 2025-06-12 17:55:50 +09:00
parent 9621169d57
commit 05e8fcd0b0
5 changed files with 59 additions and 11 deletions

View File

@ -41,7 +41,9 @@ 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)
{
try
{ {
await (type switch await (type switch
{ {
@ -50,6 +52,12 @@ public class StorageService
STORAGE_TYPE.Session => _js.InvokeVoidAsync("sessionStorage.removeItem", key), STORAGE_TYPE.Session => _js.InvokeVoidAsync("sessionStorage.removeItem", key),
_ => throw new ArgumentException("Invalid storage type") _ => throw new ArgumentException("Invalid storage type")
}); });
return true;
}
catch
{
return false;
}
} }
} }

View File

@ -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>
} }

View File

@ -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("로그아웃 처리 중 오류가 발생했습니다.");
}
}
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 636 B

File diff suppressed because one or more lines are too long