-
Notifications
You must be signed in to change notification settings - Fork 0
[Refactor] 네이티브 SDK 로그인 구현 및 브릿지 이관 #187
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bbd9c42
♻️ [refactor] 웹에서 로그인 관련 로직 브릿지로 이관
yummjin a7b933a
✨ [feat] 브릿지 추가 정의 및 authStorage 추가
yummjin ad4b5b5
✨ [feat] 네이티브 SDK 사용해서 로그인 구현
yummjin 877c04c
♻️ [refactor] authStorage 및 관련 로직 제거 및 브릿지 인터페이스 수정
yummjin 1380c59
♻️ [refactor] Webview 및 Web 환경에 따라 동일 동작할 수 있도록 분기 구현
yummjin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import * as AppleAuthentication from 'expo-apple-authentication'; | ||
|
|
||
| /** | ||
| * expo-apple-authentication으로 Apple 로그인 실행 | ||
| * authorizationCode를 반환하며, 백엔드 API 호출은 Web에서 처리 | ||
| */ | ||
| export const performAppleLogin = async (): Promise<{ | ||
| authorizationCode: string; | ||
| }> => { | ||
| const result = await AppleAuthentication.signInAsync({ | ||
| requestedScopes: [ | ||
| AppleAuthentication.AppleAuthenticationScope.FULL_NAME, | ||
| AppleAuthentication.AppleAuthenticationScope.EMAIL, | ||
| ], | ||
| }); | ||
|
|
||
| if (!result.authorizationCode) { | ||
| throw new Error('Apple로부터 인증 코드를 받지 못했습니다.'); | ||
| } | ||
|
|
||
| return { authorizationCode: result.authorizationCode }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { login } from '@react-native-kakao/user'; | ||
|
|
||
| /** | ||
| * Kakao native SDK로 로그인 실행 | ||
| * accessToken을 반환하며, 백엔드 API 호출은 Web에서 처리 | ||
| */ | ||
| export const performKakaoLogin = async (): Promise<{ | ||
| accessToken: string; | ||
| }> => { | ||
| const result = await login(); | ||
|
|
||
| if (!result.accessToken) { | ||
| throw new Error('카카오 액세스 토큰을 받지 못했습니다.'); | ||
| } | ||
|
|
||
| return { accessToken: result.accessToken }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import type { ExpoConfig } from 'expo/config'; | ||
| import appJson from './app.json'; | ||
|
|
||
| const config: ExpoConfig = { | ||
| ...appJson.expo, | ||
| plugins: [ | ||
| ...(appJson.expo.plugins ?? []), | ||
| [ | ||
| '@react-native-kakao/core', | ||
| { nativeAppKey: process.env.KAKAO_NATIVE_APP_KEY ?? '' }, | ||
| ], | ||
| ], | ||
| }; | ||
|
|
||
| export default config; | ||
|
Member
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. 우선순위가 높은 작업은 아니지만, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,67 +1,72 @@ | ||
| import { useCallback, useRef } from 'react'; | ||
| import { useCallback } from 'react'; | ||
|
|
||
| import { useKakaoLogin } from '@/features/auth/model'; | ||
| import { useFlow } from '@/app/routes/stackflow'; | ||
|
|
||
| import { postSocialLogin } from '@/features/auth/api/postSocialLogin'; | ||
| import { useKakaoLogin } from '@/features/auth/model/useKakaoLogin'; | ||
|
|
||
| import type { AuthProvider } from '@/shared/api/models/auth'; | ||
| import { AUTH_PROVIDER } from '@/shared/constants/auth'; | ||
| import { | ||
| APPLE_AUTHORIZE_URL, | ||
| // KAKAO_AUTHORIZE_URL, | ||
| // KAKAO_REST_API_KEY, | ||
| } from '@/shared/constants/url'; | ||
| import { APPLE_AUTHORIZE_URL } from '@/shared/constants/url'; | ||
| import { bridge } from '@/shared/lib/bridge'; | ||
| import { isWebView } from '@/shared/lib/env'; | ||
| import { useAuthStore } from '@/shared/store/auth'; | ||
|
|
||
| export const useSocialLogin = () => { | ||
| const { handleKakaoLogin } = useKakaoLogin({ | ||
| onSuccess: () => {}, | ||
| onError: (loginError) => { | ||
| console.error(`로그인 실패 ${loginError.message}`); | ||
| }, | ||
| }); | ||
|
|
||
| const loginWithKakao = () => { | ||
| handleKakaoLogin(); | ||
| const { replace } = useFlow(); | ||
| const { setAccessToken } = useAuthStore(); | ||
| const { handleKakaoLogin } = useKakaoLogin(); | ||
|
|
||
| // const isAndroid = /Android/i.test(navigator.userAgent); | ||
| const loginWith = useCallback( | ||
| async (provider: AuthProvider) => { | ||
| if (!isWebView()) { | ||
| if (provider === AUTH_PROVIDER.KAKAO) { | ||
| handleKakaoLogin(); | ||
| } else if (provider === AUTH_PROVIDER.APPLE) { | ||
| window.location.href = APPLE_AUTHORIZE_URL; | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| // if (isAndroid) { | ||
| // window.location.href = `https://kauth.kakao.com/oauth/authorize?response_type=code&client_id=${KAKAO_REST_API_KEY}&redirect_uri=${KAKAO_AUTHORIZE_URL}`; | ||
| // } else { | ||
| // handleKakaoLogin(); | ||
| // } | ||
| }; | ||
| const type = provider === AUTH_PROVIDER.KAKAO ? 'kakao' : 'apple'; | ||
|
|
||
| const isDisabledRef = useRef(false); | ||
| const timeoutRef = useRef<number | null>(null); | ||
| const authResult = await bridge.socialLogin(type); | ||
| if (!authResult.success) { | ||
| console.error(`OAuth 실패: ${authResult.message}`); | ||
| return; | ||
| } | ||
|
|
||
| const preventMultipleClicks = (ms: number) => { | ||
| if (timeoutRef.current) { | ||
| window.clearTimeout(timeoutRef.current); | ||
| } | ||
| const request = | ||
| provider === AUTH_PROVIDER.KAKAO | ||
| ? { accessToken: authResult.accessToken } | ||
| : { authorizationCode: authResult.authorizationCode }; | ||
| const response = await postSocialLogin(provider, request); | ||
|
|
||
| isDisabledRef.current = true; | ||
| timeoutRef.current = window.setTimeout(() => { | ||
| isDisabledRef.current = false; | ||
| timeoutRef.current = null; | ||
| }, ms); | ||
| }; | ||
| const { accessToken, status, crewId } = response.result; | ||
| setAccessToken(accessToken); | ||
|
|
||
| const loginWithApple = () => { | ||
| if (isDisabledRef.current) return; | ||
| preventMultipleClicks(2000); | ||
| window.location.href = `${APPLE_AUTHORIZE_URL}&state=${window.location.origin}`; | ||
| }; | ||
|
|
||
| const loginWith = useCallback(async (provider: AuthProvider) => { | ||
| switch (provider) { | ||
| case AUTH_PROVIDER.KAKAO: | ||
| return loginWithKakao(); | ||
| case AUTH_PROVIDER.APPLE: | ||
| return loginWithApple(); | ||
| default: | ||
| throw new Error('Invalid provider'); | ||
| } | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, []); | ||
| switch (status) { | ||
| case 'PENDING_TERMS': | ||
| replace('TermAgreePage', {}, { animate: false }); | ||
| break; | ||
| case 'PENDING_ONBOARDING': | ||
| replace('OnboardingPage', {}, { animate: false }); | ||
| break; | ||
| case 'ACTIVE': | ||
| replace('HomePage', {}, { animate: false }); | ||
| break; | ||
| case 'WAITING_FOR_APPROVE': | ||
| case 'APPROVED_PENDING_CONFIRM': | ||
| case 'REJECTED_PENDING_CONFIRM': | ||
| replace('CrewJoinStatusPage', { crewId }, { animate: false }); | ||
| break; | ||
| case 'KICKED_PENDING_CONFIRM': | ||
| replace('CrewBannedStatusPage', {}, { animate: false }); | ||
| break; | ||
| } | ||
| }, | ||
| [handleKakaoLogin] | ||
| ); | ||
|
|
||
| return { loginWith }; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.