Skip to content

Commit

Permalink
fix: separate login url retrieve to function
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinho1011 committed Feb 18, 2024
1 parent 89f4201 commit 5b20728
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/routes/Auth/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5b20728

Please sign in to comment.