Skip to content

Commit 3696852

Browse files
committed
feat: 구글 로그인 수정
1 parent 40933da commit 3696852

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

auth.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/components/login/login-form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default function LoginForm() {
2121
const CLIENT_ID = process.env.NEXT_PUBLIC_AUTH_KAKAO_ID;
2222
authUrl = `https://kauth.kakao.com/oauth/authorize?client_id=${CLIENT_ID}&redirect_uri=${callbackUrl}&response_type=code`;
2323
} else if (provider === 'google') {
24-
const CLIENT_ID = process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID;
24+
const CLIENT_ID = process.env.NEXT_PUBLIC_AUTH_GOOGLE_ID;
2525
const SCOPE = 'openid email profile';
2626
authUrl = `https://accounts.google.com/o/oauth2/v2/auth?client_id=${CLIENT_ID}&redirect_uri=${callbackUrl}&response_type=code&scope=${SCOPE}`;
2727
}

0 commit comments

Comments
 (0)