Skip to content

Commit

Permalink
Merge pull request #136 from boostcampwm2023/feat/134-logout-api-connect
Browse files Browse the repository at this point in the history
[Feat] 로그인 유지 및 로그아웃 로직 변경 구현
  • Loading branch information
dbwhdtjr0457 authored Nov 23, 2023
2 parents a23ded6 + fe1b983 commit 118fe04
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
13 changes: 10 additions & 3 deletions FE/src/App.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import React, { useLayoutEffect } from "react";
import Reset from "styled-reset";
import { createGlobalStyle } from "styled-components";
import { useRecoilValue } from "recoil";
import { useRecoilState } from "recoil";
import userAtom from "./atoms/userAtom";
import Header from "./components/Header/Header";
import HomePage from "./pages/HomePage";
Expand Down Expand Up @@ -35,7 +35,14 @@ const GlobalStyle = createGlobalStyle`
`;

function App() {
const userState = useRecoilValue(userAtom);
const [userState, setUserState] = useRecoilState(userAtom);

useLayoutEffect(() => {
const accessToken = localStorage.getItem("accessToken");
if (accessToken) {
setUserState({ ...userState, isLogin: true, accessToken });
}
}, []);

return (
<div className='App'>
Expand Down
1 change: 1 addition & 0 deletions FE/src/components/LoginModal/LoginModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function LoginModal() {
isLogin: true,
accessToken: data.accessToken,
}));
localStorage.setItem("accessToken", data.accessToken);
} else {
errorRef.current.innerText = data.message;
}
Expand Down
1 change: 1 addition & 0 deletions FE/src/components/SideBar/SideBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ function SideBar() {
isLogin: false,
accessToken: "",
}));
localStorage.removeItem("accessToken");
}}
>
로그아웃
Expand Down

0 comments on commit 118fe04

Please sign in to comment.