Intro
ํ๋ก์ ํธ๊ฐ ์์์ผ๊น์ง๋ผ ์ฃผ๋ง์๋ ์ด์ฌํ ์์ ์ ํ๋ค.
firebase authentication์ผ๋ก ๋ก๊ทธ์ธ ์ฐ๋์ ํ๊ณ firebase firestore๋ ์ฐ๊ฒฐํด DB ์ค์ ํ๋ ค ํ์ผ๋ firestore๋ ์ฐ๋์ ์คํจํ๋ค ใ
ํ๋ก์ ํธ ์งํ์ํฉ
React Native Firebase
React Native Firebase | React Native Firebase
Welcome to React Native Firebase! To get started, you must first setup a Firebase project and install the "app" module. React Native Firebase is the officially recommended collection of packages that brings React Native support for all Firebase services on
rnfirebase.io
react native ํ๋ก์ ํธ์ firebase๋ฅผ ์ค์นํ๋ ๋ฐฉ๋ฒ์ ๋ํด์ ์์ ์ฌ์ดํธ์ ์์ธํ๊ฒ ๋์์๋ค.
์ฐ์ ํ๋ก์ ํธ์ firebase๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด์ ๊ธฐ๋ณธ์ ์ผ๋ก @react-native-firebase/app์ ์ค์นํด์ผ ํ๋ค.
๊ทธ ์ธ์ Authentication์ด๋ firestore์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ๋ค๋ฅธ ํจํค์ง๋ค์ ์ถ๊ฐ๋ก ์ค์นํด์ฃผ๋ฉด ๋๋ค.
npm install --save @react-native-firebase/app
๊ทธ ํ, firebase์์ ๋ฐ์ GoogleService-Info.plist ํ์ผ์ /ios/{projectName}.xcodeproj ์ ์ ์ฅํ๋ค.
pod install์ ํ๋ฉด ์์ฒญ๋ ์ค๋ฅ๊ฐ ๋์ค๋๋ฐ ์ ๋งํฌ์์ ํ๋์ฉ ํด๊ฒฐํด์ฃผ๋ฉด ๋๋ค.
Firebase Authentication
Firebase Authentication ๊ธฐ๋ฅ์ ์ฌ์ฉํ๋ฉด ๊ฐ๋จํ๊ฒ ๋ก๊ทธ์ธ/ํ์๊ฐ์ ์ ๊ตฌํํ ์ ์๋ค.
SNS ๋ก๊ทธ์ธ ๊ธฐ๋ฅ๋ ์ ๊ณตํ๊ณ ์๋ค.
- firebase-auth ์ค์น
npm install @react-native-firebase/auth
cd ios/ && pod install
firebase-auth์์ onAuthStateChanged ๋ชจ๋์ ํตํด ํ์ฌ ์ธ์ฆ ์ํ๋ฅผ ๊ตฌ๋ ํ๊ณ ์ํ๊ฐ ๋ณ๊ฒฝ๋ ๋๋ง๋ค ์ด๋ฒคํธ๋ฅผ ์์ ํ ์ ์๋ ๋ฉ์๋๋ฅผ ์ ๊ณตํ๋ค.
์ฑ์ ๋๊ฐ๋ค ๋ค์ด์๋ ์ธ์ฆ ์ํ๊ฐ ์ฑ ์บ์์ ์ ์ฅ๋๋ค.
import React, { useState, useEffect } from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { MainStack, LoginStack } from './src/router';
import auth from '@react-native-firebase/auth';
function App(): React.JSX.Element {
const [initializing, setInitializing] = useState(true);
const [user, setUser] = useState();
function onAuthStateChanged(user) {
setUser(user);
if (initializing) setInitializing(false);
}
useEffect(() => {
const subscriber = auth().onAuthStateChanged(onAuthStateChanged);
return subscriber;
}, []);
if (initializing) return null;
return (
<NavigationContainer>{user ? <MainStack /> : <LoginStack />}</NavigationContainer>
);
}
export default App;
๋ก๊ทธ์ธ/ํ์๊ฐ์ ํ๋ฉด ๊ตฌํ
์ฌ์ฉ์๊ฐ ๋ก๊ทธ์ธ๋์ด ์์ ๊ฒฝ์ฐ, Home ํ์ด์ง๋ก ์ด๋ํ๋ฉฐ ๋ก๊ทธ์ธ๋์ง ์์์ ๊ฒฝ์ฐ ๋ก๊ทธ์ธ ํ์ด์ง์ผ๋ก ์ด๋ํ๋๋ก ๊ตฌํํ์๋ค.
๋ก๊ทธ์ธ/ํ์๊ฐ์ ์ ๊ฒฝ์ฐ, ๊ฐ๋จํ validation์ ์ถ๊ฐํ์๋ค.
๋ชจ๋ ํ๋์ ๊ฐ์ด ์ ๋ ฅ์ด ๋์๋์ง ์ฒดํฌ -> ์ด๋ฉ์ผ ํ์์ด ๋ง๋์ง -> ๋น๋ฐ๋ฒํธ ์๋ฆฌ์ ์ฒดํฌ -> ์ฝ๊ด ๋์ ์ฒดํฌ๊ฐ ๋์ด์์ ๊ฒฝ์ฐ ๋ง ํ์๊ฐ์ ๊ฐ๋ฅ ๋ฑ...
์๊ฐ์ Google, Facebook ๋ก๊ทธ์ธ์ ๊ตฌํํ์ง ๋ชปํ๋ค.
Firebase Firestore
Firebase Authentication์ ์ ์์ ์ผ๋ก ์ค์นํ๊ณ ๋์ํ์๋๋ฐ Firestore๋ฅผ ์ค์นํ๋ ๊ณผ์ ์์ ๋ง์ ์ค๋ฅ๋ฅผ ๋ง๋ฌ๊ณ ๊ฒฐ๊ตญ ๊ธฐ๊ฐ ๋ด์ ํด๊ฒฐํ์ง ๋ชปํ๋ค.
โ ๏ธ [!] The following Swift pods cannot yet be integrated as static libraries: The Swift pod FirebaseCoreInternal depends upon GoogleUtilities , which does not define modules. To opt into those targets generating module maps (which is necessary to import them from Swift when building as static libraries), you may set use_modular_headers! globally in your Podfile, or specify :modular_headers => true for particular dependencies. |
- Podfile
pod 'GoogleUtilities', :modular_headers => true
:modular_headers => true๋ก ์ค์ ํ๋ผ๋ ์ค๋ฅ๊ฐ ๋์ค๊ณ ์ด๋ฅผ Podfile์ ์ ์ผ๋ฉด
Module ‘FirebaseCore’ not found |
์ด๋ฐ ์ค๋ฅ๊ฐ ๋์๋ค.
pod 'FirebaseCore', :modular_headers => true
๊ณ์ Podfile์ ์์ ํ๊ณ Pod ์ด๊ธฐํ/์ค์น๋ฅผ ๋ฐ๋ณตํ๋๋ผ ๋ง์ ์๊ฐ์ด ์์๋๋ค ใ ใ
โ ๏ธ [!] The following Swift pods cannot yet be integrated as static libraries: The Swift pod FirebaseFirestore depends upon FirebaseCoreExtension and FirebaseFirestoreInternal, which do not define modules. To opt into those targets generating module maps (which is necessary to import them from Swift when building as static libraries), you may set use_modular_headers! globally in your Podfile, or specify :modular_headers => true for particular dependencies. |
use_modular_headers! # ๋ชจ๋ Pods์ ๋ํด ๋ชจ๋ ํค๋ ์ฌ์ฉ ์ค์
pod 'FirebaseFirestore', :modular_headers => true
๊ณ์ ๋ฐ๋ณต...ํ๋ค๊ฐ ๊ฒฐ๊ตญ ํด๊ฒฐํ์ง ๋ชปํ๋ค.
๋ณธ ํ๋ก์ ํธ๋ฅผ ํ ๋ Flipper๋ฅผ ์ฌ์ฉํ๊ณ ์์๊ณ Firebase๋ Flipper์ ํจ๊ป ์ฌ์ฉํ ์ ์์๋ค.
๊ทธ๋์ ์ด๋ฌํ ๋ฌธ์ ๋ค๋ ์์ธ์ด ์์์ ์ง๋ ๋ชจ๋ฅธ๋ค.
+ ์ถํ์ ํ ํ๋ก์ ํธ์์ ๋ค์ Firestore๋ฅผ ์ฐ๋ํ๋ ์์ ์ ๋์ ํด ๋ณด์๋๋ฐ ๊ทธ๋ ๋๋์ด ์ฑ๊ณตํ์๋ค!
์ด๋ฌํ ์คํจ๋ค์ด ๊ฒช๊ณ ์์ํ๊ฒ ์ฑ๊ณตํ ์ ์์๋ ๊ฒ ๊ฐ๋ค.
๊ทธ๋ฆฌ๊ณ ํ ํ๋ก์ ํธ์์ React-native๊ฐ ๋ฒ์ ์ด ์ฌ๋ผ๊ฐ๋ฉด์ ๋ด ๋งฅ๋ถ๋ ์ํํธ์จ์ด ์ ๋ฐ์ดํธ๊ฐ ํ์ํ๋๋ฐ ๋งฅ๋ถ ์ํํธ์จ์ด ๋ฒ์ ๋ฌธ์ ์์์๋..?

๋ง๋ฌด๋ฆฌ
์ด๋ฒ ํ๋ก์ ํธ๋ firestore๋ฅผ ์ฌ์ฉํด๋ณด์๋ ์์ฌ์ firebase๋ฅผ ์ฐ๋ํ๋ ๊ณผ์ ์์ ๋๋ฌด ๋ง์ ์๊ฐ์ด ์๋ชจ๋์ด ๊ตฌํํด์ผ ํ ์ฌํญ๋ค์ ๋ชจ๋ ๊ตฌํํ์ง ๋ชปํ๋ค. ๊ทธ๋๋ ์ค๋ฅ๋ฅผ ํด๊ฒฐํ๋ ๊ณผ์ ์์ ๋ง์ด ๋ฐฐ์ ๋ ์๊ฐ์ด์๋ค. ๊ณต์ ๋ฌธ์์ ์ค๋ฅ ๋ด์ฉ์ ๊ผผ๊ผผํ ์ฝ์ด์ผ๊ฒ ๋ค๊ณ ๋๊ผ๊ณ ์ธ๋ด์ฌ๋ ๊ธฐ๋ฅผ ์ ์์๋ค. ํ..