Skip to content

Commit

Permalink
Merge pull request #132 from KakaoTech-BootCamp-Team-2/dev
Browse files Browse the repository at this point in the history
fix:채팅방 쿠키로 접속하게 설정
  • Loading branch information
Hanjuri authored Sep 10, 2024
2 parents d9f9c4e + 0c55fcf commit bb5ecef
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/pages/chat/ChatMain.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,23 @@ import dummyChatList from "./dummyChatData/dummyChatList";
function ChatMain() {
const [chatList, setChatList] = useState([])
const [selectedChatRoom, setSelectedChatRoom] = useState(null);
const nowUser = localStorage.getItem("username");

const getUsernameFromCookieOrLocalStorage = () => {
// 쿠키에서 username 값을 먼저 확인
const usernameFromCookie = document.cookie
.split("; ")
.find((row) => row.startsWith("username="))
?.split("=")[1];

// 쿠키에 값이 없으면 localStorage에서 가져오기
if (usernameFromCookie) {
return usernameFromCookie;
} else {
return localStorage.getItem("username");
}
};
const nowUser = getUsernameFromCookieOrLocalStorage();
console.log('cookie-get:', nowUser);


useEffect(() => {
Expand Down

0 comments on commit bb5ecef

Please sign in to comment.