React Nativedでアプリを開発しています。
https://github.com/StephenGrider/ReactNativeReduxCasts/tree/master/manager
上記のソースコードをサンプルにして、マネージャーが雇用者を登録していく仕様なのですが、一覧表示は公に公開されることを想定しています。
現在、React Nativeで作ったアプリのフォームからFirebaseのデータベースにプッシュができなくて困っています。
ライブラリ:
Firebase本家ではなく、「react-native-firebase」を使っています。
https://rnfirebase.io/
できていること
・Google-Services.plistの読み込みは成功しているはずです。
Authenticationは通るので
・return console.log(name, phone, shift)だとちゃんとコンソール上に表示されます。やはり、DataBaseとの接続に失敗していると考えられます。
redux/uiActions.js
JavaScript
1/** 2 * Builds an action to save employee 3 */ 4export const employeeUpdate = ({ prop, value }) => ({ 5 type: 'employee_update', 6 payload: { prop, value } 7}); 8 9export const employeeCreate = ({ name, phone, shift }) => { 10 const { currentUser } = firebase.auth(); 11 12 return () => { 13 firebase.database().ref(`/employee/`) 14 .push({ name, phone, shift }) 15 .then(() => navigation.navigate("Home")); 16 }; 17}; 18
プロセス
- Firebaseにデータベースを作成しました
- ルールを設定しました
{ "rules": { "users": { "$uid": { ".read": "$uid === auth.uid", ".write": "$uid === auth.uid" } } } }
なにか設定が足りていないのでしょうか。
どうぞよろしくお願いします。
追記①
JavaScript
1export default class App extends React.Component<*, State> { 2 authSubscription: () => any; 3 state: State; 4 5 constructor() { 6 super(); 7 // Set the default state of the component 8 this.state = { 9 loading: true, 10 }; 11 } 12 13 componentWillMount() { 14 const config = { 15 apiKey: 'AIzaSXXXXXXXXXXXXXXXo0OW0c', 16 authDomain: 'XXXXXXXX.firebaseapp.com', 17 databaseURL: 'https://poXXXXXXX.firebaseio.com', 18 projectId: 'XXXXXXXX1', 19 storageBucket: 'pXXXXXXXXXX.appspot.com', 20 messagingSenderId: '9XXXXXXXXXXXX61' 21 }; 22 23 firebase.initializeApp(config); 24 } 25・・・
App.jsにconfigを追記してみましたが、効果はないようです。
Deprecation: Calling 'initializeApp()' for apps that are already initialised natively is unnecessary, use 'firebase.app()' instead to access the already initialized default app instance.
このエラーが出たので
JavaScript
1 componentWillMount() { 2 firebase.app(); 3 }
こちらも試して見ましたが、やはり無理みたいです。。。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/02/14 12:39
2018/02/14 12:44
2018/02/14 13:20
2018/02/14 13:38
2018/02/14 14:30
2018/02/14 14:37
2018/02/15 02:17