diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 03d9549..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/jsLinters/eslint.xml b/.idea/jsLinters/eslint.xml deleted file mode 100644 index 541945b..0000000 --- a/.idea/jsLinters/eslint.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/pages/chat/ChatMain.jsx b/src/pages/chat/ChatMain.jsx index 1fbdeb5..1a53cbf 100644 --- a/src/pages/chat/ChatMain.jsx +++ b/src/pages/chat/ChatMain.jsx @@ -11,23 +11,13 @@ function ChatMain() { const [chatList, setChatList] = useState([]) const [selectedChatRoom, setSelectedChatRoom] = useState(null); - 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 getUsername = () => { + const usernameFromLocalStorage = localStorage.getItem('username'); + return usernameFromLocalStorage || "kakao_3691500201"; }; - const nowUser = getUsernameFromCookieOrLocalStorage(); - console.log('cookie-get:', nowUser); + const nowUser = getUsername(); useEffect(() => { console.log(nowUser,'현재 사용자') diff --git a/src/pages/chat/ChatRoom.jsx b/src/pages/chat/ChatRoom.jsx index cfadbe3..ca3c7c5 100644 --- a/src/pages/chat/ChatRoom.jsx +++ b/src/pages/chat/ChatRoom.jsx @@ -10,7 +10,14 @@ const ChatRoom = (props) => { const { uuid, name } = props; const [messages, setMessages] = useState([]); const [message, setMessage] = useState(""); - const currentUsername = localStorage.getItem('username'); // 현재 사용자 설정 + + // 현재 사용자 이름 설정 함수 + const getUsername = () => { + const usernameFromLocalStorage = localStorage.getItem('username'); + return usernameFromLocalStorage || "kakao_3691500201"; + }; + + const currentUsername = getUsername(); // 현재 사용자 이름 설정 const roomId = uuid; const [stompClient, setStompClient] = useState(null); // STOMP 클라이언트 객체 저장 @@ -88,11 +95,12 @@ const ChatRoom = (props) => { message: message, }; + // 서버로 메시지 발행 (전송) stompClient.send("/pub/messages", {}, JSON.stringify(chatMessage)); console.log("전송된 메시지:", chatMessage); - setMessage(""); + setMessage(""); // 입력창 초기화 }; return (