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

[AUD-11] 애플 로그인 Redirection 구현 #3

Merged
merged 11 commits into from
Jan 21, 2024
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ dist-ssr
*.njsproj
*.sln
*.sw?

.env
.env.local
.env.development.local
.env.test.local
.env.production.local
1 change: 1 addition & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './login';
24 changes: 24 additions & 0 deletions src/constants/login.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const socialLoginProvider = {
apple: {
url: 'https://appleid.apple.com/auth/authorize',
config: {
client_id: import.meta.env.VITE_APPLE_CLIENT_ID,
redirect_uri: import.meta.env.VITE_APPLE_REDIRECT_URL,
response_type: 'code id_token',
state: 'origin:web',
scope: 'name email',
response_mode: 'form_post',
m: 11,
v: '1.5.4',
// TODO: 임시 속성들. 추후 논의 후 수정해야 함
},
},
kakao: {
url: 'https://kauth.kakao.com/oauth/authorize',
config: {
client_id: import.meta.env.VITE_KAKAO_CLIENT_ID,
redirect_uri: import.meta.env.VITE_KAKAO_REDIRECT_URL,
response_type: 'code',
},
},
};
34 changes: 29 additions & 5 deletions src/pages/LoginPage.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
import { socialLoginProvider } from '@/constants';
import { SocialLoginProviderType } from '@/types';

export default function LoginPage() {
const KAKAO_REST_API_KEY = ''; // TODO: 임시 KEY
const KAKAO_REDIRECT_URI = 'http://localhost:5173/redirect'; // TODO: 임시 URL
const kakaoLoginLink = `https://kauth.kakao.com/oauth/authorize?client_id=${KAKAO_REST_API_KEY}&redirect_uri=${KAKAO_REDIRECT_URI}&response_type=code`;
const makeQueryString = (
config: Record<string, string | number | boolean>,
) => {
return Object.entries(config)
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
.join('&');
};

const makeSocialLoginUrl = (provider: SocialLoginProviderType) => {
const { url, config } = socialLoginProvider[provider];
const queryString = makeQueryString(config);

return `${url}?${queryString}`;
};

const handleKakaoLogin = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 함수를 각각 따로 만들기보다는 매개변수로 platform 을 받아서 붙이는 게 어떤가요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지금은 �함수가 비슷하지만 혹시나 이후 코드가 더 추가될까봐 일단은 분리해두었습니다..!
코드가 비슷할 것 같긴 하지만
만약에 코드 내용이 많이 달라진다면 굳이 함수를 하나로 만들 필요가 없을 것 같아서요

window.location.href = makeSocialLoginUrl('kakao');
};

const handleAppleLogin = () => {
window.location.href = makeSocialLoginUrl('apple');
};

const handleLogin = () => (window.location.href = kakaoLoginLink);
return (
<div>
<button type="button" onClick={handleLogin}>
<button type="button" onClick={handleKakaoLogin}>
카카오로 로그인
</button>
<button type="button" onClick={handleAppleLogin}>
애플로 로그인
</button>
</div>
);
}
22 changes: 4 additions & 18 deletions src/pages/MainPage.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
import reactLogo from '@/assets/react.svg';
import { useTmap } from '@/hooks/useTmap';

import viteLogo from '/vite.svg';

function MainPage() {

const { tmapModuleRef, mapContainerRef } = useTmap({
const { /*tmapModuleRef, */ mapContainerRef } = useTmap({
mapId: 'tmap',
latitude: 37.5652045,
longitude: 126.98702028,
});

return (
<div>
<div ref={mapContainerRef} />
<a href="https://vitejs.dev" target="_blank">
<img src={viteLogo} className="logo" alt="Vite logo" />
</a>
<a href="https://react.dev" target="_blank">
<img
src={reactLogo}
className="logo react"
alt="React logo"
/>
</a>
</div>
<div>
<div ref={mapContainerRef} />
</div>
);
}

Expand Down
7 changes: 0 additions & 7 deletions src/pages/RedirectionPage.tsx

This file was deleted.

1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './login';
1 change: 1 addition & 0 deletions src/types/login.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type SocialLoginProviderType = 'apple' | 'kakao';
10 changes: 10 additions & 0 deletions vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
interface ImportMetaEnv {
readonly VITE_KAKAO_CLIENT_ID: string;
readonly VITE_KAKAO_REDIRECTION_URL: string;
readonly VITE_APPLE_CLIENT_ID: string;
readonly VITE_APPLE_REDIRECT_URL: string;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

첨부드린 공식문서에 나온 내용인데, 이걸 실제 ImportMeta interface 에 추가로 적용해주셔야 합니다.

interface ImportMetaEnv {
    readonly VITE_KAKAO_CLIENT_ID: string;
    readonly VITE_KAKAO_REDIRECTION_URL: string;
    readonly VITE_APPLE_CLIENT_ID: string;
    readonly VITE_APPLE_REDIRECT_URL: string;
}

interface ImportMeta {
  readonly env: ImportMetaEnv
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 아이고.. 그렇군요 수정하겠스빈다
공식문서를... 제대로 안읽은걸 들켰군요 ..


interface ImportMeta {
readonly env: ImportMetaEnv;
}