Skip to content

Commit

Permalink
Merge pull request #131 from Hanjuri/feature/#49
Browse files Browse the repository at this point in the history
fix:채팅방 쿠키설정 변경
  • Loading branch information
Hanjuri authored Sep 10, 2024
2 parents ba59876 + 4761414 commit 0c55fcf
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 0c55fcf

Please sign in to comment.