Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature-059: 소셜 로그인 진행중 #47

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import SearchResult from './pages/SearchResultPage';
import SignInPage from '@/pages/SignInPage';
import SignUpPage from '@/pages/SignUpPage';
import SignUpSuccessPage from '@/pages/SignUpSuccessPage';
import SocialAccountPage from '@/pages/SocialAccountPage';
import SummaryPage from '@/pages/SummaryPage';

// Layouts
Expand Down Expand Up @@ -45,6 +46,7 @@ const App = () => {
<Route path="/sign-up/success" element={<SignUpSuccessPage />} />
<Route path="/find-email" element={<FindEmailPage />} />
<Route path="/find-password" element={<FindPasswordPage />} />
<Route path="/social-account" element={<SocialAccountPage />} />
</>
)}

Expand All @@ -54,7 +56,6 @@ const App = () => {
<Route path="/search" element={<SearchPage />} />
<Route path="/search/result" element={<SearchResult />} />
<Route path="/profile" element={<ProfilePage />} />

</>
)}

Expand Down
7 changes: 6 additions & 1 deletion src/apis/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ export const checkEmailAPI = (data: CheckEmailRequest) => {
data,
);
};

export const joinAPI = (data: JoinRequest) => {
return axios.post<APIResponse<JoinResponse>>(PREFIX + '/join', data);
};
};

export const socialAccountAPI = (code: string) => {
return axios.get(`/sign-up/success?code=${code}`);
};
5 changes: 2 additions & 3 deletions src/pages/SignInPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,12 @@ const SignInPage: React.FC = () => {
}
};

const redirect_uri = `${location.origin}/sign-up/success`; //Redirect URI
const redirect_uri = `${location.origin}/social-account`; //Redirect URI
const KAKAO_KEY = '77ddf1baeb87f4a9752ed437db43cd96'; //kakao REST API KEY
const NAVER_CLIENT_ID = 'qR4Npp1ui69SCF6nAJd2';
const STATE = 'flase';
// oauth 요청 URL
const kakaoURL = `https://kauth.kakao.com/oauth/authorize?client_id=${KAKAO_KEY}&redirect_uri=${redirect_uri}&response_type=code`;
const naverURL = `https://nid.naver.com/oauth2.0/authorize?response_type=code&client_id=${NAVER_CLIENT_ID}&state=${STATE}&redirect_uri=${redirect_uri}`;
const naverURL = `https://nid.naver.com/oauth2.0/authorize?response_type=code&client_id=${NAVER_CLIENT_ID}&redirect_uri=${redirect_uri}`;

const handleKakaoLogin = () => {
window.location.href = kakaoURL;
Expand Down
31 changes: 31 additions & 0 deletions src/pages/SocialAccountPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';

import { socialAccountAPI } from '@/apis/user';

const SocialAccountPage = () => {
const { search } = useLocation();

const callAPI = async (code: string) => {
try {
console.log(await socialAccountAPI(code));
} catch (e) {
console.error(e);
}
};

useEffect(() => {
const params = new URLSearchParams(search);
const code = params.get('code');

if (!code) {
return;
}

callAPI(code);
}, [search]);

return <div />;
};

export default SocialAccountPage;
Loading