-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat: 로그아웃 및 로컬스토리지 구성
- Loading branch information
Showing
8 changed files
with
105 additions
and
58 deletions.
There are no files selected for viewing
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
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,15 +1,46 @@ | ||
import styles from "./Main.module.scss"; | ||
import { Link } from "react-router-dom"; | ||
import { Link, useNavigate } from "react-router-dom"; | ||
import main_logo from "../../assets/main-logo.png"; | ||
import { useAtom } from "jotai"; | ||
import { accessTokenAtom } from "../../store/jotaiAtoms"; | ||
|
||
export default function Login() { | ||
const [accessToken, setAccessToken] = useAtom(accessTokenAtom); | ||
const router = useNavigate(); | ||
|
||
const logout = () => { | ||
if (confirm("정말 로그아웃 하시겠습니까?")) { | ||
localStorage.removeItem("accessToken"); | ||
setAccessToken(""); | ||
router("/"); | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
<div className={styles.root}> | ||
<Link to="/login" className={styles.linkBtn_container}> | ||
<button className={styles.linkBtn}> | ||
<img src={main_logo} alt="main-logo" /> | ||
</button> | ||
</Link> | ||
</> | ||
<button | ||
className={styles.loginBtn} | ||
onClick={() => router("/login")} | ||
> | ||
로그인 | ||
</button> | ||
<button | ||
className={styles.logoutBtn} | ||
onClick={() => logout()} | ||
> | ||
로그아웃 | ||
</button> | ||
<button | ||
className={styles.frameBtn} | ||
onClick={() => router("/framelist")} | ||
> | ||
프레임 만들기 | ||
</button> | ||
</div> | ||
); | ||
} |
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,3 +1,8 @@ | ||
import { atom } from 'jotai'; | ||
|
||
export const accessTokenAtom = atom(""); | ||
export const accessTokenAtom = atom(localStorage.getItem('accessToken') || ''); | ||
|
||
export const updateToken = (newToken) => { | ||
localStorage.setItem('accessToken', newToken); | ||
accessTokenAtom[1](newToken); | ||
}; |