Skip to content

Commit a9d81a1

Browse files
authored
Merge pull request codeit-13-3team#109 from rover1523/feature/kakao
Refactor:배포 환경에 맞게 redirectUrl 변경
2 parents 2e4a3ed + 4a7810c commit a9d81a1

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

src/lib/kakaoSignupAuth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export const getKakaoSignupAuthUrl = () => {
22
const clientId = process.env.NEXT_PUBLIC_KAKAO_REST_API_KEY;
33
const redirectUrl = process.env.NEXT_PUBLIC_KAKAO_SIGNUP_REDIRECT_URI;
4-
console.log('✅ clientId:', clientId); // 디버깅용
5-
console.log('✅ redirectUrl:', redirectUrl); // 디버깅용
4+
console.log('✅ clientId:', clientId);
5+
console.log('✅ redirectUrl:', redirectUrl);
66
if (!clientId || !redirectUrl) {
77
throw new Error('카카오 로그인 환경변수가 설정되지 않았습니다.');
88
}

src/pages/kakaologin.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@ import React from 'react';
22
import { useRouter } from 'next/router';
33
import { useKakaoLogin } from '@/hooks/useKakaoLogin';
44
import { KakaosignupButton } from '@/components/button/KakaoSignupButton';
5+
import useAuthStore from '@/stores/authStores';
6+
7+
const setIsLoggedIn = useAuthStore.getState().setIsLoggedIn;
58

69
const KakaoRedirectPage = () => {
710
const router = useRouter();
811
const { code } = router.query;
912

1013
const { data, isError, error, isLoading } = useKakaoLogin(code as string);
1114

12-
// ✅ error를 any로 캐스팅해서 response 사용 가능
1315
const err = error as any;
1416

1517
if (isLoading) return <div>로그인 처리 중입니다...</div>;
1618

17-
// ✅ 조건부 렌더링: 등록되지 않은 사용자일 경우
1819
if (
1920
isError &&
2021
err?.response?.status === 403 &&
@@ -32,6 +33,7 @@ const KakaoRedirectPage = () => {
3233
if (data) {
3334
const { accessToken } = data;
3435
localStorage.setItem('accessToken', accessToken);
36+
setIsLoggedIn(true);
3537
router.push('/');
3638
}
3739

src/pages/oauth/signup/kakao.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ const KakaoSignupPage = () => {
2121
setError,
2222
} = useForm<FormValues>();
2323

24-
const redirectUri =
25-
process.env.NEXT_PUBLIC_KAKAO_SIGNUP_REDIRECT_URI || 'http://localhost:3000/oauth/signup/kakao';
24+
const redirectUri = process.env.NEXT_PUBLIC_KAKAO_SIGNUP_REDIRECT_URI;
2625

2726
const onSubmit = async ({ nickname }: FormValues) => {
2827
if (!code || typeof code !== 'string') {
@@ -40,7 +39,7 @@ const KakaoSignupPage = () => {
4039
{
4140
nickname,
4241
redirectUri,
43-
token: code, // ✅ access_token이 아니라 code를 서버로 전달
42+
token: code,
4443
},
4544
{
4645
headers: {

0 commit comments

Comments
 (0)