-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* user store 생성 * 로그인 페이지 라우트 가드 * 로그인 페이지 input 수정 * typescript * 홈화면 로그인 상태에 따라 nav 변경 * 로그인 라우터 가드 * 라우트 가드 함수 생성
- Loading branch information
Showing
8 changed files
with
85 additions
and
59 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,24 @@ | ||
import { User } from "@/store/userStore"; | ||
|
||
export const LOGIN_ID = "login"; | ||
export const LOGOUT_ID = "logout"; | ||
|
||
export const Navigator = () => ` | ||
export const Navigator = (user: User) => { | ||
document.querySelector("#root")?.addEventListener("click", (e) => { | ||
if (e.target instanceof HTMLAnchorElement) { | ||
if (e.target.id === LOGOUT_ID) { | ||
localStorage.removeItem("user"); | ||
} | ||
} | ||
}); | ||
|
||
return ` | ||
<nav class="bg-white shadow-md p-2 sticky top-14"> | ||
<ul class="flex justify-around"> | ||
<li><a href="/" class="text-blue-600">홈</a></li> | ||
<li><a href="/" class="text-blue-600 font-bold">홈</a></li> | ||
<li><a href="/profile" class="text-gray-600">프로필</a></li> | ||
<li><a id=${LOGOUT_ID} href="/login" class="text-gray-600">로그아웃</a></li> | ||
<li><a id=${user?.username ? LOGOUT_ID : LOGIN_ID} href="/login" class="text-gray-600">${user?.username ? "로그아웃" : "로그인"}</a></li> | ||
</ul> | ||
</nav> | ||
`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export interface User { | ||
username?: string; | ||
email?: string; | ||
bio?: string; | ||
} | ||
|
||
const createUserStore = () => { | ||
return { | ||
getUser() { | ||
const localStorageUser = localStorage.getItem("user"); | ||
const user = localStorageUser ? JSON.parse(localStorageUser) : null; | ||
|
||
return user; | ||
}, | ||
setUser(user: User) { | ||
localStorage.setItem("user", JSON.stringify(user)); | ||
}, | ||
}; | ||
}; | ||
|
||
export const userStore = createUserStore(); |