-1

I am running an react-native chat app example from Even Bacon. I can enter my name successfully. But when I enter a chat message, then I have a warning about firebase, the chat message was not taken:

enter image description here

Here is the Chat.js:

import React, { Component} from 'react';
import {View, StyleSheet } from 'react-native';
import { GiftedChat } from 'react-native-gifted-chat';
import Fire from '../Fire';

class Chat extends React.Component {
    static navigationOptions = ({ navigation}) => ({
        title: (navigation.state.params || {}).name || 'Chat!',
    });

    state = {
        messages: [],
    };

    componentDidMount() {
        Fire.shared.on(message =>
              this.setState(previousState => ({
                messages: GiftedChat.append(previousState.messages, message),
              }))
        );
    }

    componentWillUnmount() {
      Fire.shared.off();
    }

    get user() {
      // return our name and our UID for GiftedChat to parse
      return {
          name: this.props.navigation.state.params.name,
          _id: Fire.shared.uid,
      };
    }

    render() {
        return (
            <GiftedChat 
              messages={this.state.messages}
              onSend={Fire.shared.send}
              user={this.user}
            /> 
        );
    }
}

const styles = StyleSheet.create({});



export default Chat;
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
user938363
  • 9,990
  • 38
  • 137
  • 303

1 Answers1

1

Make sure you have set up your database rules like this

{
  "rules": {
    ".read": true,
    ".write": true
  }
}
Ritviz Sharma
  • 306
  • 1
  • 9
  • 2
    While this may/will remove the error message, any such instructions should always come with a warning that these rules give everyone (who knows the URL of your database) complete read and write access to all data. It should only be used in (very early stages) of the development cycle. – Frank van Puffelen Jan 26 '19 at 04:10
  • @FrankvanPuffelen totally agree to you on that. – Ritviz Sharma Jan 26 '19 at 04:19