-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from all commits
1415f83
951586d
00ad7b2
c03a2b9
53fd627
37d1fbb
c5b88eb
ad7af0c
e7d3fc8
4605e30
e559818
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,9 @@ dist-ssr | |
*.njsproj | ||
*.sln | ||
*.sw? | ||
|
||
.env | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './login'; |
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', | ||
}, | ||
}, | ||
}; |
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 = () => { | ||
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> | ||
); | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './login'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type SocialLoginProviderType = 'apple' | 'kakao'; |
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; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 첨부드린 공식문서에 나온 내용인데, 이걸 실제 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
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아 아이고.. 그렇군요 수정하겠스빈다 |
||
|
||
interface ImportMeta { | ||
readonly env: ImportMetaEnv; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기도 함수를 각각 따로 만들기보다는 매개변수로 platform 을 받아서 붙이는 게 어떤가요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
지금은 �함수가 비슷하지만 혹시나 이후 코드가 더 추가될까봐 일단은 분리해두었습니다..!
코드가 비슷할 것 같긴 하지만
만약에 코드 내용이 많이 달라진다면 굳이 함수를 하나로 만들 필요가 없을 것 같아서요