@@ -58,21 +58,26 @@ export const { handlers, signIn, signOut, auth } = NextAuth({
5858 if ( ! parsed . success ) return null ;
5959 const { provider, code } = parsed . data ;
6060
61- const backendUrl = `${ process . env . BACKEND_API_URL } /auth/oauth/${ provider } ?code=${ code } ` ;
62- console . log ( backendUrl ) ;
61+ const backendUrl = `${ process . env . BACKEND_API_URL } /auth/oauth/${ provider } ?code=${ encodeURIComponent ( code ) } ` ;
62+ const method = provider === 'google' ? 'GET' : 'POST' ;
63+ console . log ( `[${ provider } ] OAuth Request:` , method , backendUrl ) ;
64+
6365 try {
66+ // Google uses GET, Kakao uses POST
6467 const res = await fetch ( backendUrl , {
65- method : 'POST' ,
68+ method,
6669 headers : { 'Content-Type' : 'application/json' } ,
6770 } ) ;
6871
72+ console . log ( `[${ provider } ] Response status:` , res . status ) ;
73+
6974 if ( ! res . ok ) {
7075 const error = await res . json ( ) ;
71- console . log ( error ) ;
76+ console . error ( `[ ${ provider } ] Backend error:` , error ) ;
7277 throw new Error ( 'Backend verification failed' ) ;
7378 }
7479 const { data } = await res . json ( ) ;
75- console . log ( data ) ;
80+ console . log ( `[ ${ provider } ] Success data:` , data ) ;
7681
7782 return {
7883 userId : data . userId ,
@@ -148,6 +153,11 @@ export const { handlers, signIn, signOut, auth } = NextAuth({
148153 } ;
149154 }
150155
156+ // Only attempt refresh if we have a refresh token (user is logged in)
157+ if ( ! token . refreshToken ) {
158+ return token ;
159+ }
160+
151161 if ( Date . now ( ) < ( token . accessTokenExpires ?? 0 ) - TOKEN_REFRESH_BUFFER ) {
152162 return token ;
153163 }
0 commit comments