Skip to content

Commit

Permalink
refactor: modify sign in button action code
Browse files Browse the repository at this point in the history
  • Loading branch information
timepresent95 committed Oct 9, 2024
1 parent f53d5bb commit a21f326
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 102 deletions.
1 change: 1 addition & 0 deletions src/business/services/authorizeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const authorizeAgents: Record<AuthAgent, () => Promise<AuthToken>> = {
kakao: authorizeWithKakao,
};

//FIXME: 에러 처리를 어떻게 할 지 고민이 필요 함
export async function authorizeWithAgent(agent: AuthAgent) {
return await authorizeAgents[agent]();
}
Expand Down
9 changes: 4 additions & 5 deletions src/constants/auth.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Platform } from 'react-native';
import { isIOS } from '@/utils/platform';

export const GOOGLE_OAUTH_APP_GUID =
Platform.OS === 'ios'
? '297990896037-v5u61qtoirlh4kh1838qdf8sdmotfsku'
: '297990896037-761s2d4s9h6fhf60qaa37icjba865i0m';
export const GOOGLE_OAUTH_APP_GUID = isIOS()
? '297990896037-v5u61qtoirlh4kh1838qdf8sdmotfsku'
: '297990896037-761s2d4s9h6fhf60qaa37icjba865i0m';

export const SIGN_IN_WITH_GOOGLE_CONFIG = {
issuer: 'https://accounts.google.com',
Expand Down
52 changes: 11 additions & 41 deletions src/screen/SignInScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,33 @@ import React from 'react';
import {
Image,
ImageBackground,
NativeModules,
Platform,
Pressable,
SafeAreaView,
StyleSheet,
View,
} from 'react-native';

import { authorizeWithAgent } from '@/business/services/authorizeService';
import { authRouteNames, colors } from '@/constants';
import { TextMedium, TextSemiBold } from '@/entities/fonts';
import { AuthStackParams } from '@/navigations/stack/AuthStackNavigator';
import useNavigationStore from '@/store/stores/navigationStore';
import { signInWithGoogle } from '@/utils/oauth';
import { AuthAgent } from '@/types';
import { isIOS } from '@/utils/platform';

type SignInScreenProps = NativeStackScreenProps<
AuthStackParams,
typeof authRouteNames.SIGN_IN
>;

//XXX: 배포까지 완료된 후에 Firestore를 통한 구글 로그인 방식 제거해야 함
//TODO: ios, android kakao sign in 에러 처리를 동일하게 할 수 있도록 수정 필요
const { KakaoLoginModule, AppleLoginModule } = NativeModules;

function SignInScreen({ navigation }: SignInScreenProps) {
const { navigate } = useNavigationStore();

function handleSignIn() {
navigate(navigation, authRouteNames.JOIN1);
function handleSignIn(agent: AuthAgent) {
authorizeWithAgent(agent).then(() =>
navigate(navigation, authRouteNames.JOIN1),
);
}
const handleKakaoSignIn = () => {
KakaoLoginModule.signInWithKakao()
.then((token: any) => {
console.log(token);
})
.catch((error: Error) => {
console.log(error);
});
};

const handleGoogleSignIn = async () => {
try {
const { idToken } = await signInWithGoogle();
console.log(idToken ?? 'idToken is null');
} catch (error) {
console.error(error);
}
};

const handleAppleSignIn = async () => {
try {
const { idToken }: { idToken: string } =
await AppleLoginModule.loginWithApple();
console.log('Apple Login Success:', idToken);
} catch (error) {
console.error('Apple Login Failed:', error);
}
};

return (
<ImageBackground
Expand All @@ -79,7 +49,7 @@ function SignInScreen({ navigation }: SignInScreenProps) {
<View className="my-4">
<Pressable
className="flex h-11 flex-row items-center rounded-lg bg-white px-4"
onPress={() => handleSignIn()}>
onPress={() => handleSignIn('google')}>
<Image
source={require('@/assets/img/google-logo.png')}
className="h-5 w-5"
Expand All @@ -91,7 +61,7 @@ function SignInScreen({ navigation }: SignInScreenProps) {
<Pressable
className="my-3 flex h-11 flex-row items-center rounded-lg px-4"
style={[styles.kakaoLoginButton]}
onPress={() => handleSignIn()}>
onPress={() => handleSignIn('kakao')}>
<Image
source={require('@/assets/img/kakao-logo.png')}
className="h-5 w-5"
Expand All @@ -100,10 +70,10 @@ function SignInScreen({ navigation }: SignInScreenProps) {
Kakao 계정으로 로그인
</TextSemiBold>
</Pressable>
{Platform.OS === 'ios' && (
{isIOS() && (
<Pressable
className="flex h-11 flex-row items-center rounded-lg px-4"
onPress={() => handleSignIn()}
onPress={() => handleSignIn('apple')}
style={[styles.appleLoginButton]}>
<Image
source={require('@/assets/img/apple-logo.png')}
Expand Down
56 changes: 0 additions & 56 deletions src/utils/oauth.ts

This file was deleted.

0 comments on commit a21f326

Please sign in to comment.