react-native-google-signing은 구글 로그인과 애플 로그인을 할 수 있게 만들어진 react-native 라이브러리이다.
Github -> 공식 문서에 설명이 잘 되있다
구글 Outh2 Document
나는 firebase를 사용하지 않아서 firebase가 없는 경우의 가이드를 참고했다.
Firebase가 없을 경우
1. Get an OAuth client ID.
2. Add a URL scheme to your project
Configure a Google API Project
Google Cloud Platform 에 프로젝트 만들고 WebClintId, IosClientId(firebase를 이용안할경우)저장
yarn add @react-native-google-signin/google-signin
Cocoapods가 있을경우
Podfile에 넣고 pod-install
pod 'GoogleSignIn', '~> 6.1.0'
webClientId 는 firebase 콘솔에 앱을 만들경우 자동으로 만들어진다!
만들어진 아이디는 여기에서 확인이 가능하다.
import {GoogleSignin} from '@react-native-google-signin/google-signin';
const googleSigninConfigure = () => {
GoogleSignin.configure({
webClientId:'웹클라이언트 아이디',
iosClientId:'ios클라이언트 아이디', //파이어베이스 서버 이용을 안할경우 필요한듯
});
};
useEffect(() => {
googleSigninConfigure();
}, []);
import {
GoogleSignin,
GoogleSigninButton, //구글 로그인 이미지 버튼
} from '@react-native-google-signin/google-signin';
const onGoogleButtonPress = async () => {
const userInfo = await GoogleSignin.signIn();
};
<TouchableOpacity onPress={onGoogleButtonPress}>
<Text>구글 로그인</Text>
</TouchableOpacity>
{
idToken: string,
serverAuthCode: string,
scopes: Array<string>, // on iOS this is empty array if no additional scopes are defined
user: {
email: string,
id: string,
givenName: string,
familyName: string,
photo: string, // url
name: string // full name
}
}
Error:A non-recoverable sign in failure occurred
해결