Skip to content

Commit

Permalink
Merge pull request #142 from FinalDoubleTen/FE-60--feat/NewUser/NewLo…
Browse files Browse the repository at this point in the history
…gin/Kakao

Fe 60  feat/new user/new login/kakao
  • Loading branch information
jseo9732 authored Jan 11, 2024
2 parents 9023f4f + 10f55f3 commit b9c42de
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 32 deletions.
18 changes: 9 additions & 9 deletions src/@types/member.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ interface MemberInfo {
nickname: string;
email: string;
profileImageUrl: string | null;
ageType:
| 'TEENAGER'
| 'TWENTIES'
| 'THIRTIES'
| 'FOURTIES'
| 'ABOVE_FIFTIES'
| 'DEFATULT'
| null;
genderType: 'MALE' | 'FEMALE' | 'NON_BINARY' | null;
ageType: string | null;
// | 'TEENAGER'
// | 'TWENTIES'
// | 'THIRTIES'
// | 'FOURTIES'
// | 'ABOVE_FIFTIES'
// | 'DEFATULT'
genderType: string | null;
// 'MALE' | 'FEMALE' | 'NON_BINARY' | 'DEFATULT';
survey: Survey | null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/api/authClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import axios from 'axios';
import { postLogout } from './auth';

const authClient = axios.create({
baseURL: import.meta.env.VITE_SERVER_URL,
baseURL: `${import.meta.env.VITE_SERVER_URL}api/`,
headers: {
'Content-Type': 'application/json',
},
Expand Down
2 changes: 1 addition & 1 deletion src/api/client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios';

const client = axios.create({
baseURL: import.meta.env.VITE_SERVER_URL,
baseURL: `${import.meta.env.VITE_SERVER_URL}api/`,
headers: {
'Content-Type': 'application/json',
},
Expand Down
8 changes: 2 additions & 6 deletions src/components/Auth/Login/AuthButtons/KakaoLoginButton.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { KakaoIcon } from '@components/common/icons/Icons';

const KakaoLoginButton = () => {
const VITE_KAKAO_LOGIN_TEST_API_KEY = import.meta.env
.VITE_KAKAO_LOGIN_TEST_API_KEY;
const REDIRECT_URI = `${window.location.href}/kakao`;
const KAKAO_LOGIN_URL = `https://kauth.kakao.com/oauth/authorize?client_id=${VITE_KAKAO_LOGIN_TEST_API_KEY}&redirect_uri=${REDIRECT_URI}&response_type=code`;

return (
<a
href={KAKAO_LOGIN_URL}
href={`${import.meta.env.VITE_SERVER_URL}oauth2/authorization/kakao`}
// href="http://localhost:8080/oauth2/authorization/kakao"
className="body3 mb-2 flex h-14 w-full items-center justify-center gap-2 rounded-lg bg-[#fee304] p-2 text-['#3B1E1E']">
<KakaoIcon />
카카오로 로그인
Expand Down
44 changes: 44 additions & 0 deletions src/components/Auth/Login/KakaoLogin.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { UserInfoState } from '@recoil/Auth.atom';
import { setItem } from '@utils/localStorageFun';
import { useEffect } from 'react';
import { useNavigate, useSearchParams } from 'react-router-dom';
import { useSetRecoilState } from 'recoil';

const KakaoLogin = () => {
const setUserInfo = useSetRecoilState(UserInfoState);
const navigate = useNavigate();

const [searchParams, _] = useSearchParams();
const nickname = searchParams.get('nickname');
const email = searchParams.get('email');
const gender = searchParams.get('gender');
const age_range = searchParams.get('age_range');
const accessToken = searchParams.get('token');
const profile_image = searchParams.get('profile_image');
const signup = searchParams.get('signup');

useEffect(() => {
if (accessToken) {
setItem('accessToken', accessToken);
setUserInfo({
nickname: nickname!,
email: email!,
profileImageUrl: profile_image,
ageType: age_range,
genderType: gender,
survey: null,
});
if (signup) {
navigate('/signup/success');
} else {
navigate('/');
}
} else {
alert('로그인에 실패했습니다. 다시 시도해주세요.');
navigate('/login');
}
}, []);
return <>카카오 로그인 중입니다.</>;
};

export default KakaoLogin;
3 changes: 2 additions & 1 deletion src/components/Auth/Login/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import LoginLogo from './LoginLogo';
import LoginForm from './LoginForm';
import AuthButtonsWrapper from './AuthButtons/AuthButtonsWrapper';
import KakaoLogin from './KakaoLogin';

export { LoginLogo, LoginForm, AuthButtonsWrapper };
export { LoginLogo, LoginForm, AuthButtonsWrapper, KakaoLogin };
15 changes: 2 additions & 13 deletions src/pages/login/loginKakao.page.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import { useEffect } from 'react';
import { KakaoLogin } from '@components/Auth/Login';

const LoginKakao = () => {
const code = new URL(window.location.href).searchParams.get('code');

useEffect(() => {
console.log(code);
try {
// const res = postKakaoLogin();
} catch (err) {
console.log('카카오 로그인 중 에러 발생');
}
}, []);

return <div>잠시만 기다려주세요</div>;
return <KakaoLogin />;
};

export default LoginKakao;
8 changes: 7 additions & 1 deletion src/pages/signup/signupInfo.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ const SignupInfo = () => {

return (
<div className="flex h-[95vh] flex-col">
<BackBox showBack showSkip />
<BackBox
showBack
showSkip
skipHandler={() => {
navigate('/');
}}
/>
<AuthTitle
title={
<>
Expand Down

0 comments on commit b9c42de

Please sign in to comment.