File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -46,25 +46,27 @@ const AuthPage = () => {
4646
4747 if ( authorizationCode ) {
4848 try {
49- await mutateAsync ( {
49+ const response = await mutateAsync ( {
5050 socialType,
5151 authorizationCode,
5252 redirectUrl : REDIRECT_URI || "" ,
5353 } ) ;
5454
55- safeLocalStorage . set ( IS_LOGINED , "true" ) ;
56-
57- router . replace ( redirectUrl || PATH . HOME ) ;
58- safeSessionStorage . remove ( REDIRECT_URL_KEY ) ;
59- } catch ( error ) {
60- if ( isAxiosErrorResponse ( error ) ) {
61- safeLocalStorage . set ( TOKEN_KEY , error . response ?. data . message || "" ) ;
55+ // 회원가입 필요
56+ if ( response . code === 40402 ) {
57+ safeLocalStorage . set ( TOKEN_KEY , response ?. message || "" ) ;
6258 router . replace ( PATH . SIGNUP ) ;
6359
6460 return ;
6561 }
6662
67- console . log ( error ) ;
63+ safeLocalStorage . set ( IS_LOGINED , "true" ) ;
64+
65+ router . replace ( redirectUrl || PATH . HOME ) ;
66+ safeSessionStorage . remove ( REDIRECT_URL_KEY ) ;
67+ } catch ( error ) {
68+ alert ( "에러가 발생했습니다." ) ;
69+ console . error ( error ) ;
6870 router . replace ( PATH . HOME ) ;
6971 }
7072 } else {
Original file line number Diff line number Diff line change @@ -44,9 +44,7 @@ type LoginRequest = {
4444 redirectUrl : string ;
4545} ;
4646
47- type LoginResponse = {
48- data : null ;
49- } ;
47+ type LoginResponse = { code : number ; message : string } ;
5048
5149export type LoginMutationOptions < TData > = Omit <
5250 UseMutationOptions < TData , Error , LoginRequest > ,
@@ -58,12 +56,6 @@ export type LoginMutationOptions<TData> = Omit<
5856export const useLoginMutation = ( options ?: LoginMutationOptions < LoginResponse > ) => {
5957 return useMutation ( {
6058 mutationFn : async ( params : LoginRequest ) => {
61- // const response = await instance.post<LoginResponse>(API_URL.USER.LOGIN, params);
62-
63- // document.cookie = "co:11";
64-
65- // return response.data;
66-
6759 const res = await fetch ( "/api/login" , {
6860 method : "POST" ,
6961 headers : {
@@ -73,10 +65,6 @@ export const useLoginMutation = (options?: LoginMutationOptions<LoginResponse>)
7365 body : JSON . stringify ( params ) ,
7466 } ) ;
7567
76- if ( ! res . ok ) {
77- throw new Error ( "로그인 요청 실패" ) ;
78- }
79-
8068 return res . json ( ) ;
8169 } ,
8270 ...options ,
You can’t perform that action at this time.
0 commit comments