- react-native-firebase의 모듈 설치시 항상 ios 폴더가서
pod update실행
-
npm install --save @react-native-firebase/app
-
cd ios & pod install
-
open codeLabRN.xcworkspace
-
파이어베이스 로그인 후 iOS 앱에 Firebase 추가
-
Podfile열고 target 'codeLabRN' do의 end끝나기 전에 아래 문구 추가
- ```pod 'Firebase/Analytics'``
- pod update 실행
-
앱 실행해서 설치 확인
import auth from '@react-native-firebase/auth';
class RnFirebase extends Component {
componentDidMount() {
auth().signInAnonymously()
.then( authInfo => {
console.log('authInfo', authInfo);
})
.catch(error => {
if (error.code === 'auth/operation-not-allowed') {
console.log('Enable anonymous in your firebase console.');
}
console.error(error);
});
}
}- 이메일 로그인
- https://rnfirebase.io/auth/usage
- firebase console -> Authentication -> 이메일/비밀번호
import auth from '@react-native-firebase/auth';
class RnFirebase extends Component {
componentDidMount() {
// 이메일로 가입시키고 로그인
auth()
.createUserWithEmailAndPassword('<test1></test1>@gmail.com', 'SuperSecretPassword!')
.then( authInfo => {
console.log('authInfo', authInfo);
})
.catch(error => {
if (error.code === 'auth/email-already-in-use') {
console.log('That email address is already in use!');
}
if (error.code === 'auth/invalid-email') {
console.log('That email address is invalid!');
}
console.error(error);
});
}
} - 콘솔 Authentication 에서 사용자 확인
- Users탭에서 비밀번호 재설정 가능(이메일로 변경 링크보냄)
- Templates탭에서 비밀번호 재설정 이메일 양식도 수정 가능
- npm i @react-native-firebase/database
- https://rnfirebase.io/database/usage
- database().ref().set({})
import database from '@react-native-firebase/database';
class RnFirebase extends Component {
componentDidMount() {
database()
.ref('/users/1') // insert할 객체(Document)
.set({ // insert할 데이터
userId: 1,
name: 'david',
email: "david@email.com"
})
.then(() => console.log('Data set.'));
}
}- database().ref().once()
import database from '@react-native-firebase/database';
class RnFirebase extends Component {
componentDidMount() {
// 데이터 베이스 생성
database()
.ref('users') // select할 객체
.once('value') // 실시간이 아닌 한번만 수행
.then(snapshot => {
console.log('User data: ', snapshot.val()); // 데이터 값만 가져옴
});
}
}- database().ref().on()
database()
.ref('users')
.on('value', snapshot => {
console.log('User data: ', snapshot.val());
});- 파이어베이스 가입 및 연동
- 파이어베이스 사용법








