Skip to content

Commit

Permalink
refactor: redirect uri 도메인 오리진을 얻어서 붙이는 방식으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
jinhokim98 committed Nov 20, 2024
1 parent 6c6ab93 commit 4587836
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
9 changes: 3 additions & 6 deletions client/src/apis/request/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {ADMIN_API_PREFIX, USER_API_PREFIX} from '@apis/endpointPrefix';
import {requestGet, requestGetWithoutResponse, requestPostWithoutResponse} from '@apis/fetcher';
import {WithEventId} from '@apis/withId.type';

import getKakaoRedirectUrl from '@utils/getKakaoRedirectUrl';

export const requestPostAuthentication = async ({eventId}: WithEventId) => {
await requestPostWithoutResponse({
baseUrl: BASE_URL.HD,
Expand Down Expand Up @@ -32,14 +34,9 @@ export const requestKakaoClientId = async () => {
};

export const requestGetKakaoLogin = async (code: string) => {
const redirectUri =
process.env.NODE_ENV === 'development'
? 'http://localhost:3000' + process.env.KAKAO_REDIRECT_URI
: 'https://haengdong.pro' + process.env.KAKAO_REDIRECT_URI;

await requestGetWithoutResponse({
baseUrl: BASE_URL.HD,
endpoint: `/api/login/kakao?code=${code}&redirect_uri=${redirectUri}`,
endpoint: `/api/login/kakao?code=${code}&redirect_uri=${getKakaoRedirectUrl()}`,
});

return null;
Expand Down
8 changes: 3 additions & 5 deletions client/src/hooks/useLoginPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {useLocation, useNavigate} from 'react-router-dom';

import {useAuthStore} from '@store/authStore';

import getKakaoRedirectUrl from '@utils/getKakaoRedirectUrl';

import {ROUTER_URLS} from '@constants/routerUrls';

import useRequestGetKakaoClientId from './queries/auth/useRequestGetKakaoClientId';
Expand All @@ -21,12 +23,8 @@ const useLoginPage = () => {
const goKakaoLogin = async () => {
const queryResult = await requestGetClientId();
const clientId = queryResult.data?.clientId;
const redirectUri =
process.env.NODE_ENV === 'development'
? 'http://localhost:3000' + process.env.KAKAO_REDIRECT_URI
: 'https://haengdong.pro' + process.env.KAKAO_REDIRECT_URI;

const link = `https://kauth.kakao.com/oauth/authorize?client_id=${clientId}&redirect_uri=${redirectUri}&response_type=code`;
const link = `https://kauth.kakao.com/oauth/authorize?client_id=${clientId}&redirect_uri=${getKakaoRedirectUrl()}&response_type=code`;
window.location.href = link;
};

Expand Down
5 changes: 5 additions & 0 deletions client/src/utils/getKakaoRedirectUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const getKakaoRedirectUrl = () => {
return window.location.origin + process.env.KAKAO_REDIRECT_URI;
};

export default getKakaoRedirectUrl;

0 comments on commit 4587836

Please sign in to comment.