I have a firebase database linked up to two apps, one being an iOS app and another being a web app coded in node.js which is a basic algorithm that sets data to the database
add async in main()
and await before
follow my code
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
var fsconnect = FirebaseFirestore.instance;
myget() async {
var d = await fsconnect.collection("students").get();
// print(d.docs[0].data());
for (var i in d.docs) {
print(i.data());
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Firebase Firestore App'),
),
body: Column(
children: <Widget>[
RaisedButton(
child: Text('send data'),
onPressed: () {
fsconnect.collection("students").add({
'name': 'sarah',
'title': 'xyz',
'email': 'sarah@gmail.com',
});
print("send ..");
},
),
RaisedButton(
child: Text('get data'),
onPressed: () {
myget();
print("get data ...");
},
)
],
),
));
}
}
If you are starting out a react-native app and seeing this issue, then you have to follow all the instructions listed in firebase (when you setup iOS/android app) or the instructions @ React-native google auth android DEVELOPER_ERROR Code 10 question
You are probably invoking firebase
before the app is initialized. All calls to firebase.
must come after .initializeApp();
firebase.initializeApp(config);
var db = firebase.firestore();
YOU CALL THIS IN JADE: firebase.initializeApp(config); IN THE BEGIN OF THE FUNC
script.
function signInWithGoogle() {
firebase.initializeApp(config);
var googleAuthProvider = new firebase.auth.GoogleAuthProvider
firebase.auth().signInWithPopup(googleAuthProvider)
.then(function (data){
console.log(data)
})
.catch(function(error){
console.log(error)
})
}
My problem was because I added a second parameter:
AngularFireModule.initializeApp(firebaseConfig, 'reservas')
if I remove the second parameter it works fine:
AngularFireModule.initializeApp(firebaseConfig)
This may not be best answer but, I had to initialize app with admin and firebase like below. I use admin for it's own purposes and firebase as well.
const firebase = require("firebase");
const admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);
firebase.initializeApp(functions.config().firebase);
// Get the Auth service for the default app
var authService = firebase.auth();
function createUserWithEmailAndPassword(request, response) {
const email = request.query.email;
const password = request.query.password;
if (!email) {
response.send("query.email is required.");
return;
}
if (!password) {
response.send("query.password is required.");
return;
}
return authService.createUserWithEmailAndPassword(email, password)
.then(success => {
let responseJson = JSON.stringify(success);
console.log("createUserWithEmailAndPassword.responseJson", responseJson);
response.send(responseJson);
})
.catch(error => {
let errorJson = JSON.stringify(error);
console.log("createUserWithEmailAndPassword.errorJson", errorJson);
response.send(errorJson);
});
}