доступ запрещен при записи базы данных в firebase - PullRequest
0 голосов
/ 05 ноября 2018

Проблема:

Я создаю выставочное приложение с интеграцией Firebase. Там я создал файл конфигурации для связи с базой данных. Вот так это выглядит.

import Firebase from 'firebase';
 let config = {
    apiKey: "mykey",
    authDomain: "mytrain-5beba.firebaseapp.com",
    databaseURL: "https://mytain-5beba.firebaseio.com",
    projectId: "mytain-5beba",
    storageBucket: "mytain-5beba.appspot.com",
    messagingSenderId: "myid"
  };
let app = Firebase.initializeApp(config);
export const db = app.database();

В папке сервисов я создал сервисный файл, подобный этому, для обработки грубых операций. Вот так это выглядит.

import {db} из '../config/db';

export const addItem = (item) => { db.ref ( '/') tains. нажмите ({ имя: предмет }); }

В моем компоненте В методе componentDidMount я сделал что-то подобное, чтобы проверить, работает ли соединение с базой данных погоды.

import React, { Component } from "react";
import {
  StyleSheet,
  Text,
  TextInput,
  View,
  TouchableOpacity,
  Dimensions,
  Picker,
  ListView
} from "react-native";

import {
  Ionicons,
  Foundation,
  Entypo,
  MaterialCommunityIcons,
  FontAwesome,
  MaterialIcons
} from "@expo/vector-icons";

import { Autocomplete } from "react-native-autocomplete-input";

import { addItem } from '../../services/stationService';

const { height, width } = Dimensions.get("window");
const box_width = width / 2 + 40;

export default class TicketForm extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      name: ""
    };
  }

  static navigationOptions = {
    title: "",
    headerStyle: {
      backgroundColor: "#2b78fe"
    },
    headerTintColor: "#fff",
    headerTitleStyle: {
      color: "#ffff"
    }
  };

  componentDidMount() {
    const name = "Tharindu";
    addItem(name);
  }




  render() {
    return (
      <View>
        <Text>Haiii</Text>
      </View>
    );
  }
}


});

Когда я запускаю expo start --android. Это показывает мне некоторые предупреждения, как это.

[15:52:56] [2018-11-05T10:22:51.070Z]  @firebase/database:, FIREBASE WARNING: set at /station/-LQYOMpnDzgdkj25XUDQ failed: permission_denied
- node_modules\react-native\Libraries\ReactNative\YellowBox.js:80:15 in warn
- node_modules\expo\src\Expo.js:26:41 in warn
- ... 20 more stack frames from framework internals

[15:53:01] [Unhandled promise rejection: Error: PERMISSION_DENIED: Permission denied]
- node_modules\@firebase\database\dist\index.cjs.js:13076:45 in <unknown>
- node_modules\@firebase\database\dist\index.cjs.js:690:8 in exceptionGuard
- ... 18 more stack frames from framework internals

[15:53:04] Setting a timer for a long period of time, i.e. multiple minutes, is a performance and correctness issue on Android as it keeps the timer module awake, and timers can only be called when the app is in the foreground. See https://github.com/facebook/react-native/issues/12981 for more info.
(Saw setTimeout with duration 360595ms)
- node_modules\react-native\Libraries\ReactNative\YellowBox.js:80:15 in warn
- node_modules\expo\src\Expo.js:26:41 in warn
- ... 11 more stack frames from framework internals

[15:59:03] Setting a timer for a long period of time, i.e. multiple minutes, is a performance and correctness issue on Android as it keeps the timer module awake, and timers can only be called when the app is in the foreground. See https://github.com/facebook/react-native/issues/12981 for more info.
(Saw setTimeout with duration 92226ms)
- node_modules\react-native\Libraries\ReactNative\YellowBox.js:80:15 in warn
- node_modules\expo\src\Expo.js:26:41 in warn
- ... 11 more stack frames from framework internals

Я очень новичок в этом реактивном и пожарном. Может кто-нибудь помочь мне решить эту проблему. Спасибо!

1 Ответ

0 голосов
/ 05 ноября 2018

Откройте FireBase, выберите базу данных с левой стороны. Теперь с правой стороны выберите [База данных в реальном времени] из раскрывающегося списка и измените правила на:

{
"rules": {
".read": true,
".write": true
}
}

это работает .. !!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...