2๊ฐ์ง ๋ฐฉ๋ฒ์ผ๋ก ๋ก๊ทธ์ธ์ ๊ตฌํ ํ ๊ฒ์ด๋ค. 1๋ฒ์งธ google 2๋ฒ์งธ firebase๋ฅผ ํตํด์
https://devbksheen.tistory.com/entry/React-Native-Firebase๋ก-ํ์-์ธ์ฆํ๊ธฐ
https://juzero-space.tistory.com/288
- google login
ํ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
npm install @react-native-firebase/app --save npm install @react-native-firebase/auth --save npm install @react-native-google-signin/google-signin --save
firebase์์ ์ ์ฌ๊ณต์ ์ฒด ์ถ๊ฐ.

import auth from "@react-native-firebase/auth";
import {GoogleSignin} from '@react-native-google-signin/google-signin';
export const googleSigninConfigure = () => {
GoogleSignin.configure({
webClientId:
'776883032422-hla5brdij4eenmhhat84bdtu5fbvhncc.apps.googleusercontent.com',
});
};
export const onGoogleButtonPress = async () => {
const {idToken} = await GoogleSignin.signIn();
const googleCredential = auth.GoogleAuthProvider.credential(idToken);
return auth().signInWithCredential(googleCredential);
};
const signInWithGoogle = async () => {
try {
await onGoogleButtonPress()
props.navigation.navigate("HomeScreen")
} catch(e) {
Alert.alert("๋ก๊ทธ์ธ์ ์คํจ์
จ์ต๋๋ค");
}
}
์์ ์ฝ๋๋ฅผ ์ํ๋ ๊ณณ์ ์ฝ์ ํ๋ฉด ๋


google login
- firebase email
2-1 ๋ก๊ทธ์ธ
ํ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
npm install @react-native-firebase/app --save npm install @react-native-firebase/auth --save
์์ ๊ฐ์ ๋ฐฉ๋ฒ์ผ๋ก ์ ๊ณต์ ์ฒด์ email์ ์ถ๊ฐํด ์ค๋ค.
export function signIn({email, password}) {
return auth().signInWithEmailAndPassword(email, password);
}
์ถ๊ฐ!
const [email, setEmail] = useState('');
const [password, setpassword] = useState('');
๊ฐ์ ๋ฐ์ ์ค๊ธฐ ์ํด email, password๋ฅผ ๋ฐ์ ๋ณ์ ์ถ๊ฐ (๋ณ์ ์ด๋ฆ์ ๋ค๋ฅธ ๊ฒ์ผ๋ก ํ๋ฉด ์ค๋ฅ๊ฐ ๋ฌ๋ค.)
const signInSubmit = async () => {
const info = {email, password};
try {
const {user} = await signIn(info);
console.log(user);
dispatch({type:'login',step: email})
console.log(checkLogin);
props.navigation.navigate("HomeScreen")
} catch (e) {
Alert.alert("๋ก๊ทธ์ธ์ ์คํจ์
จ์ต๋๋ค");
}
}
const signInWithGoogle = async () => {
try {
await onGoogleButtonPress()
props.navigation.navigate("HomeScreen")
} catch(e) {
Alert.alert("๋ก๊ทธ์ธ์ ์คํจ์
จ์ต๋๋ค");
}
}
์ฐธ๊ณ ๋ก secureTextEntry={true}๋ฅผ input text์์ ์ง์ด ๋ฃ์ด password์ ๋ณด์์ฑ์ ์งํจ๋ค.

2-2 ํ์๊ฐ์
export function signUp({email, password}) {
return auth().createUserWithEmailAndPassword(email, password);
}
์ถ๊ฐ
const resultMessages = {
"auth/email-already-in-use": "์ด๋ฏธ ๊ฐ์
๋ ์ด๋ฉ์ผ์
๋๋ค.",
"auth/wrong-password": "์๋ชป๋ ๋น๋ฐ๋ฒํธ์
๋๋ค.",
"auth/user-not-found": "์กด์ฌํ์ง ์๋ ๊ณ์ ์
๋๋ค.",
"auth/invalid-email": "์ ํจํ์ง ์์ ์ด๋ฉ์ผ ์ฃผ์์
๋๋ค."
}
// ์ฝ๋์ ๋ฐ๋ผ ๋ค๋ฅธ ์ค๋ฅ๋ฅผ ๋ฑ๋๋ฐ ๊ทธ๊ฑธ ์ด์ฉํ ์ค๋ฅ ๊ฐ์ฒด์ด๋ค.
const LoginScreen = (props) => {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [Checkpassword, setCheckPassword] = useState('');
const signUpSubmit = async () => { // ํ์๊ฐ์
ํจ์
const info = {email, password};
console.log(info)
try {
const {user} = await signUp(info);
console.log(user);
props.navigation.goBack()
} catch (e) {
const alertMessage = resultMessages[e.code] ?
resultMessages[e.code] : "์ ์ ์๋ ์ด์ ๋ก ํ์๊ฐ์
์ ์คํจํ์์ต๋๋ค.";
Alert.alert("ํ์๊ฐ์
์คํจ", alertMessage);
}
}

๋~
'๋ฆฌ์กํธ ๋ค์ดํฐ๋ธ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| ๋ฆฌ์กํธ๋ก ์นด์นด์ค๋งต ์ฌ์ฉํ๊ธฐ (0) | 2023.07.06 |
|---|---|
| React Native App ์ด๋ ๊ธฐ๋ก ์ฑ (0) | 2023.03.04 |
| IOS Debugger ์์ผ์ง ๋ (0) | 2023.03.02 |
| React native permmision (0) | 2023.03.02 |