66 joinGameRoom ,
77 outGameRoom ,
88} from "../api/gameRoomApi" ;
9+ import { ILoginResponse , loginUser } from "../api/userAuthApi" ;
910
1011export const useCreateRoomMutation = ( ) => {
1112 const navigate = useNavigate ( ) ;
@@ -14,7 +15,7 @@ export const useCreateRoomMutation = () => {
1415 return useMutation < ICreateGameRoomResponse , Error , { roomName : string } > ( {
1516 mutationFn : createGameRoom ,
1617 onSuccess : ( data ) => {
17- navigate ( `/gameRoom /${ data . room . id } ` ) ;
18+ navigate ( `/game/room /${ data . room . id } ` ) ;
1819 queryClient . invalidateQueries ( {
1920 queryKey : [ "gameRoomList" ] ,
2021 } ) ;
@@ -45,11 +46,16 @@ export const useJoinRoomMutation = () => {
4546
4647export const useOutRoomMutaion = ( ) => {
4748 const navigate = useNavigate ( ) ;
49+ const queryClient = useQueryClient ( ) ;
50+
4851 return useMutation ( {
4952 mutationFn : outGameRoom ,
5053 onSuccess : ( data ) => {
5154 console . log ( "방나가기 성공" , data ) ;
5255 navigate ( "/game" ) ;
56+ queryClient . invalidateQueries ( {
57+ queryKey : [ "gameRoomList" ] ,
58+ } ) ;
5359 } ,
5460
5561 onError : ( error : any ) => {
@@ -63,3 +69,21 @@ export const useOutRoomMutaion = () => {
6369 } ,
6470 } ) ;
6571} ;
72+
73+ export const useLoginSubmitMutation = ( ) => {
74+ return useMutation <
75+ ILoginResponse ,
76+ Error ,
77+ { userEmail : string ; password : string }
78+ > ( {
79+ mutationFn : loginUser ,
80+ onSuccess : ( data ) => {
81+ console . log ( data ) ;
82+ const accessToken = data ?. accessToken ;
83+ localStorage . setItem ( "accessToken" , accessToken ) ;
84+ } ,
85+ onError : ( error ) => {
86+ alert ( error . message ) ;
87+ } ,
88+ } ) ;
89+ } ;
0 commit comments