diff --git a/src/routes/Auth/login/Login.tsx b/src/routes/Auth/login/Login.tsx index 45561fa..32490ee 100644 --- a/src/routes/Auth/login/Login.tsx +++ b/src/routes/Auth/login/Login.tsx @@ -11,14 +11,22 @@ import { ABLogoIcon, AppleIcon, GoogleIcon, KakaoIcon } from '@icons/index'; import { Container, Divider, LoginButtonContainer } from './Login.styles'; -const Login = () => { - const KakaoRestApiKey = import.meta.env.VITE_KAKAO_OAUTH_KEY; - const KakaoRedirectUri = import.meta.env.VITE_KAKAO_REDIRECT_URI; - const kakaoURL = `https://kauth.kakao.com/oauth/authorize?client_id=${KakaoRestApiKey}&redirect_uri=${KakaoRedirectUri}&response_type=code`; +function getLoginUrl(type: 'kakao' | 'google' | 'apple') { + const key = import.meta.env[`VITE_${type.toUpperCase()}_OAUTH_KEY`]; + const redirectUrl = import.meta.env[`VITE_${type.toUpperCase()}_REDIRECT_URI`]; + + if (type === 'kakao') { + return `https://kauth.kakao.com/oauth/authorize?client_id=${key}&redirect_uri=${redirectUrl}&response_type=code`; + } else if (type === 'google') { + return `https://accounts.google.com/o/oauth2/v2/auth?client_id=${key}&response_type=code&redirect_uri=${redirectUrl}&scope=https://www.googleapis.com/auth/userinfo.email`; + } else { + return 'apple'; + } +} - const GoogleClientID = import.meta.env.VITE_GOOGLE_OAUTH_KEY; - const GoogleRedirectUri = import.meta.env.VITE_KAKAO_REDIRECT_URI; - const googleURL = `https://accounts.google.com/o/oauth2/v2/auth?client_id=${GoogleClientID}&response_type=token&redirect_uri=${GoogleRedirectUri}&scope=https://www.googleapis.com/auth/userinfo.email`; +const Login = () => { + const kakaoURL = getLoginUrl('kakao'); + const googleURL = getLoginUrl('google'); const handleKaKaoLogin = () => { window.location.href = kakaoURL;