Skip to content

Commit e160e57

Browse files
authored
[FRONTEND] vercel 리다이렉트 uri설정 (#50)
- vercel redirect URI 설정
1 parent 280a4bd commit e160e57

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

frontend/.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
VITE_KAKAO_CLIENT_ID=e84faf4e473047e82fd05e50e9b0c0ce
22
VITE_KAKAO_AUTH_URL=https://kauth.kakao.com/oauth/authorize
33
VITE_KAKAO_REDIRECT_URI=http://localhost:3000/oauth/kakao/redirect
4-
VITE_API_URL=https://api.com-together.org
4+
VITE_API_URL=https://api.com-together.org

frontend/KAKAO_OAUTH_SETUP.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# 카카오 OAuth 설정 가이드
2+
3+
## 1. 카카오 디벨로퍼스 콘솔 설정
4+
5+
### 앱 설정 → 플랫폼
6+
- **Web 사이트 도메인**: `https://com-together.vercel.app`
7+
8+
### 제품 설정 → 카카오 로그인 → Redirect URI
9+
다음 URI들을 모두 추가:
10+
- `http://localhost:3000/oauth/kakao/redirect` (개발용)
11+
- `https://com-together.vercel.app/oauth/kakao/redirect` (프로덕션)
12+
13+
## 2. Vercel 환경 변수 설정
14+
15+
**Vercel Dashboard → com-together → Settings → Environment Variables**
16+
17+
```
18+
VITE_KAKAO_REDIRECT_URI=https://com-together.vercel.app/oauth/kakao/redirect
19+
```
20+
21+
## 3. 설정 완료 후
22+
23+
1. Vercel에서 재배포
24+
2. 브라우저 개발자 도구 콘솔에서 로그 확인:
25+
- `🌍 현재 도메인: https://com-together.vercel.app`
26+
- `✅ 최종 사용할 REDIRECT_URI: https://com-together.vercel.app/oauth/kakao/redirect`
27+
28+
## 4. 문제 해결
29+
30+
만약 여전히 `localhost:3000`으로 리다이렉트된다면:
31+
1. 카카오 콘솔에서 URI가 제대로 등록되었는지 확인
32+
2. Vercel 환경 변수가 제대로 설정되었는지 확인
33+
3. Vercel에서 재배포 실행

frontend/src/api/userSetting/useKakaoLogin.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,31 @@ export const useKakaoLogin = () => {
6464
const initiateKakaoLogin = () => {
6565
setAuthError(null);
6666

67-
// 동적으로 리다이렉트 URI 생성 (현재 도메인 기반)
67+
// 환경 변수와 현재 도메인 정보 로깅
6868
const currentOrigin = window.location.origin;
69-
const redirectUri = import.meta.env.VITE_KAKAO_REDIRECT_URI || `${currentOrigin}/oauth/kakao/redirect`;
69+
const envRedirectUri = import.meta.env.VITE_KAKAO_REDIRECT_URI;
70+
const isLocalhost = currentOrigin.includes('localhost');
71+
const isVercel = currentOrigin.includes('vercel.app');
72+
73+
// 환경별 리다이렉트 URI 결정
74+
let redirectUri: string;
75+
if (isLocalhost) {
76+
redirectUri = envRedirectUri || 'http://localhost:3000/oauth/kakao/redirect';
77+
} else {
78+
redirectUri = envRedirectUri || `${currentOrigin}/oauth/kakao/redirect`;
79+
}
80+
81+
console.log('🌍 현재 도메인:', currentOrigin);
82+
console.log('⚙️ 환경변수 REDIRECT_URI:', envRedirectUri);
83+
console.log('🏠 로컬호스트 여부:', isLocalhost);
84+
console.log('☁️ Vercel 여부:', isVercel);
85+
console.log('✅ 최종 사용할 REDIRECT_URI:', redirectUri);
7086

7187
// prompt=login 추가로 강제 재로그인, nonce 추가로 캐시 방지
7288
const nonce = Date.now();
7389
const kakaoAuthUrl = `https://kauth.kakao.com/oauth/authorize?client_id=${import.meta.env.VITE_KAKAO_CLIENT_ID}&redirect_uri=${encodeURIComponent(redirectUri)}&response_type=code&prompt=login&nonce=${nonce}`;
7490

7591
console.log('🔗 카카오 로그인 URL:', kakaoAuthUrl);
76-
console.log('📍 리다이렉트 URI:', redirectUri);
7792

7893
window.location.href = kakaoAuthUrl;
7994
};

0 commit comments

Comments
 (0)