@@ -30,6 +30,7 @@ import type { chatRoomMessagesData } from '@apis/chatting/dto';
3030import { postUserBlockApi } from '@apis/user-block' ;
3131import type { PostUserBlockRequest } from '@apis/user-block/dto' ;
3232import { handleError } from '@apis/util/handleError' ;
33+ import { getCurrentUserId } from '@utils/getCurrentUserId' ;
3334
3435const ChatRoom : React . FC = ( ) => {
3536 const [ extendedMessages , setextendedMessages ] = useState < ExtendedMessageDto [ ] > ( [ ] ) ;
@@ -49,9 +50,8 @@ const ChatRoom: React.FC = () => {
4950 const nav = useNavigate ( ) ;
5051 const socket = useSocket ( ) ;
5152
52- const storageValue = localStorage . getItem ( 'my_id' ) ;
53- const userId = storageValue ? Number ( storageValue ) : - 1 ;
5453 const { chatRoomId } = useParams ( ) ;
54+ const currentUserId = getCurrentUserId ( ) ;
5555 const opponentInfo = useRecoilValue ( OpponentInfoAtom ) ;
5656
5757 // 메시지 수신 시 아래로 스크롤 (스크롤 아래 고정)
@@ -74,7 +74,7 @@ const ChatRoom: React.FC = () => {
7474 const postUserBlock = async ( ) => {
7575 try {
7676 const data : PostUserBlockRequest = {
77- fromUserId : userId ,
77+ fromUserId : currentUserId ,
7878 toUserId : opponentInfo ?. id || - 1 ,
7979 action : 'block' ,
8080 } ;
@@ -98,7 +98,7 @@ const ChatRoom: React.FC = () => {
9898 if ( socket ) {
9999 const data = {
100100 chatRoomId : Number ( chatRoomId ) ,
101- userId : userId ,
101+ userId : currentUserId ,
102102 } ;
103103 socket . emit ( 'leaveChatRoom' , data ) ;
104104 nav ( '/chats' , { replace : true } ) ;
@@ -141,7 +141,7 @@ const ChatRoom: React.FC = () => {
141141 // 메시지 수신 시 렌더링에 필요한 정보 추가
142142 // 이거 위에랑 합칠수없나?
143143 useEffect ( ( ) => {
144- const temp = createExtendedMessages ( allMessages , userId , opponentInfo ) ;
144+ const temp = createExtendedMessages ( allMessages , currentUserId , opponentInfo ) ;
145145 setextendedMessages ( temp ) ;
146146 } , [ allMessages ] ) ;
147147
0 commit comments