-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEAT] 유저 정보 관리 cookie로 변경 #368
Changes from 23 commits
aa638a9
a5e76ac
702eadd
a190311
94088a1
ec120fc
50de4c5
400fbee
4cea2b5
63119df
275eda1
7038f9b
443646c
a0e75c7
4327bbc
3a8ed76
da1ff91
7a4ae56
3028de5
890335e
77b0cd1
7532140
2c5b394
0698012
d86a41c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
import fetcher from './fetcher'; | ||
|
||
import { API_URL } from '@/constants/url'; | ||
import { RoomInfo, CreateOrEnterRoomResponse, Category, RoomSettingApply } from '@/types/room'; | ||
import { | ||
RoomInfo, | ||
CreateOrEnterRoomResponse, | ||
Category, | ||
RoomSettingApply, | ||
RoomAndMember, | ||
} from '@/types/room'; | ||
|
||
interface CategoryResponse { | ||
categories: Category[]; | ||
|
@@ -136,3 +142,12 @@ export const isJoinableRoom = async (roomUuid: string): Promise<{ isJoinable: bo | |
|
||
return data; | ||
}; | ||
|
||
// 사용자 정보 조회 | ||
export const getMember = async (): Promise<RoomAndMember> => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🙏 제안 🙏getMember하면 뭔가 string 값이 반환될 것 같다고 느껴지는데 getUserInfo 이런 느낌은 어떤가요?? getMember는 객체로 반환하는데 객체 키값에 member가 있어서 어색하다고 느낀 것 같아요. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네, 그렇게 수정하겠습니다! |
||
const res = await fetcher.get({ | ||
url: API_URL.getMember, | ||
}); | ||
const data = await res.json(); | ||
return data; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { useQueryClient } from '@tanstack/react-query'; | ||
import { useEffect, useRef } from 'react'; | ||
import { useRecoilState } from 'recoil'; | ||
|
||
import { | ||
readyMembersContainerLayout, | ||
|
@@ -19,24 +19,20 @@ import SillyDdangkongMedium from '@/assets/images/sillyDdangkongMedium.webp'; | |
import InviteModal from '@/components/common/InviteModal/InviteModal'; | ||
import { useGetRoomInfo } from '@/hooks/useGetRoomInfo'; | ||
import useModal from '@/hooks/useModal'; | ||
import { memberInfoState } from '@/recoil/atom'; | ||
|
||
const ReadyMembersContainer = () => { | ||
const { members, master } = useGetRoomInfo(); | ||
const { show } = useModal(); | ||
const [memberInfo, setMemberInfo] = useRecoilState(memberInfoState); | ||
const queryClient = useQueryClient(); | ||
const returnFocusRef = useRef<HTMLButtonElement>(null); | ||
|
||
const handleClickInvite = () => { | ||
show(InviteModal, { returnFocusRef }); | ||
}; | ||
|
||
// 원래 방장이 아니다 + 방장의 memberId와 내 memberId가 같다 -> 방장으로 변경 | ||
useEffect(() => { | ||
if (!memberInfo.isMaster && master.memberId === memberInfo.memberId) { | ||
setMemberInfo({ ...memberInfo, isMaster: true }); | ||
} | ||
}, [master.memberId, memberInfo, setMemberInfo]); | ||
queryClient.invalidateQueries({ queryKey: ['getMember'] }); | ||
}, [master.memberId]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🌸 칭찬 🌸오 유저정보를 서버에서 관리하니까 해당 처리가 가능하군요!!! 될 것 같긴 한데 잘 동작하는지 영상이 있으면 더 이해가 빠를 것 같아용 |
||
|
||
return ( | ||
<section css={readyMembersContainerLayout}> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { useParams } from 'react-router-dom'; | ||
import { useRecoilState } from 'recoil'; | ||
|
||
import { startGame } from '@/apis/room'; | ||
import { memberInfoState } from '@/recoil/atom'; | ||
import useGetmember from '@/hooks/useGetmember'; | ||
|
||
export const useGameStart = () => { | ||
const [memberInfo, setMemberInfo] = useRecoilState(memberInfoState); | ||
const { | ||
member: { isMaster }, | ||
} = useGetmember(); | ||
const { roomId } = useParams(); | ||
|
||
const startGameMutation = useMutation({ | ||
mutationFn: () => startGame(Number(roomId)), | ||
}); | ||
|
||
const handleGameStart = () => { | ||
if (memberInfo.isMaster) { | ||
if (isMaster) { | ||
startGameMutation.mutate(); | ||
} | ||
}; | ||
|
||
return { memberInfo, handleGameStart, setMemberInfo }; | ||
return { isMaster, handleGameStart }; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭 질문 💭
오호 이 속성을 붙여야 쿠키를 주고받을 수 있는건가요??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네, 이 속성이 있어야 쿠키가 전송이 되더라고요!