I'm trying to make a web version of my Flutter Firebase app Please Help!!!
This my current config which doesn't work
var firebase = require("firebase/app");
var firebaseConfig = {
apiKey: "xxxxxxxxxxxxxxxxxxxxxxxxx",
authDomain: "xxxxxxx.firebaseapp.com",
databaseURL: "https://xxxxxxxxx.firebaseio.com",
projectId: "xxxxxx",
storageBucket: "xxxxxxx.appspot.com",
messagingSenderId: "xxxxxxxxxxxx",
appId: "1:xxxxxxxxxx:web:xxxxxxx",
measurementId: "XXXXXXXXX"
};
firebase.initializeApp(firebaseConfig);
firebase.analytics();
I think that you need to create a new project when migrating to web
1. run this command in the terminal
flutter channel dev
2. upgrade flutter with
flutter upgrade
3. create a project
flutter create web_proj //or anything
4. add the necessary script tags in the index.html its inside your Web folder
<script src="https://www.gstatic.com/firebasejs/7.13.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.13.1/firebase-firestore.js"></script>
5. add the config inside index.html also
<script>
var firebase = require("firebase/app");
var firebaseConfig = {
apiKey: "xxxxxxxxxxxxxxxxxxxxxxxxx",
authDomain: "xxxxxxx.firebaseapp.com",
databaseURL: "https://xxxxxxxxx.firebaseio.com",
projectId: "xxxxxx",
storageBucket: "xxxxxxx.appspot.com",
messagingSenderId: "xxxxxxxxxxxx",
appId: "1:xxxxxxxxxx:web:xxxxxxx",
measurementId: "XXXXXXXXX"
};
firebase.initializeApp(firebaseConfig);
firebase.analytics();
</script>
6. add the dependencies like firestore,and others and enjoy
https://pub.dev/packages/firebase#-readme-tab-
Related
I am trying to build an flutter app purely as a website then should i use firebase initialize app twice both in index.html and main.dart?
index.html
<script>
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
var firebaseConfig = {
apiKey: "AIz...",
authDomain: "...",
databaseURL: "https://<project-name>.firebaseio.com",
projectId: "...",
storageBucket: "<project-name>.appspot.com",
messagingSenderId: "...",
appId: "...",
measurementId: "..."
};
firebase.initializeApp(firebaseConfig);
firebase.analytics();
</script>
Main.dart
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
As mentioned in the docs here you should initialize it on both places.
As mentioned in the docs they are working on a way to initialize it just on one place:
We are actively investigating ways to initialize Firebase without directly using the CDN and will update the documentation once this becomes available.
I want to collect the data of desktop app built with electron
I created the property(app+web) in firebase console then get the Firebase SDK snippet as below:
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/7.9.0/firebase-app.js"></script>
<!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#available-libraries -->
<script src="https://www.gstatic.com/firebasejs/7.9.0/firebase-analytics.js"></script>
<script>
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey: "xxxxxxxxx",
authDomain: "xxxxxxx.firebaseapp.com",
databaseURL: "xxxxxxxxx",
projectId: "xxxxxxx",
storageBucket: "xxxxxxxxx",
messagingSenderId: "xxxxxx",
appId: "xxxxxxxxx",
measurementId: "G-xxxxxxxx"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
</script>
put the configuration into the body section then try to send the logEvent
unfortunately i cannot see any stream data in real-time data collection
Any thought would be appricated.
When I import firebase on react-native then faces some issues like this.
import * as firebase from "firebase";
var firebaseConfig = {
apiKey: "[data_private]",
authDomain: "[data_private]",
databaseURL: "https://[data_private].firebaseio.com",
projectId: "[data_private]",
storageBucket: "[data_private]",
messagingSenderId: "[data_private]",
appId: "[data_private]"
};
firebase.initializeApp(firebaseConfig);
According to the docs:
First you need to install firebase package:
npm install --save firebase
Then import it using firebase/app:
// Firebase App (the core Firebase SDK) is always required and
// must be listed before other Firebase SDKs
import * as firebase from "firebase/app";
You need to add the latest version of the firebase.
You can useyarn add #react-native-firebase/app or npm i #react-native-firebase/app.
And then import firebase from it.
For reference, you can use react-native-firebase
You are using firebase package which is for web. You must use native packages like react-native-firebase
For me, this solution is working
Step 1: Install firebase using npm:
npm install --save firebase
Step 2: Add this line of code in your react native code:
var firebase = require('firebase');
var firebaseConfig = {
apiKey: "[private_data]",
authDomain: "[private_data]",
projectId: "[private_data]",
storageBucket: "[private_data]",
messagingSenderId: "[private_data]",
appId: "[private_data]",
measurementId: "[private_data]"
};
const fireApp = firebase.initializeApp(firebaseConfig);
console.log(fireApp);
I am in the middle of making a quick web app and set up a client-side firebase connection. Following the docs, I added the below code to my index.html before any other scripts are loaded in my head. However, whenever I try to get any kind of information from the database, I get the following error: #firebase/database: FIREBASE WARNING: Firebase error. Please ensure that you spelled the name of your Firebase correctly (...)
I've tried following the docs about setting up a web app again, and copied the full config info. However, I keep getting the same error. I've checked that my database name is correct in the Firebase console.
<script src="https://www.gstatic.com/firebasejs/5.8.2/firebase-app.js"</script>
<script src="https://www.gstatic.com/firebasejs/5.8.2/firebase-database.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "...",
authDomain: "...",
databaseURL: "...",
projectId: "...",
storageBucket: "...",
messagingSenderId: "..."
};
firebase.initializeApp(config);
</script>
I appreciate your time and suggestions.
Ensure you have typed correctly with extension:
<script src="https://www.gstatic.com/firebasejs/5.8.2/firebase.js"></script>
<script>
// Initialize Firebase
// TODO: Replace with your project's customized code snippet
var config = {
apiKey: "<API_KEY>",
authDomain: "<PROJECT_ID>.firebaseapp.com",
databaseURL: "https://<DATABASE_NAME>.firebaseio.com",
projectId: "<PROJECT_ID>",
storageBucket: "<BUCKET>.appspot.com",
messagingSenderId: "<SENDER_ID>",
};
firebase.initializeApp(config);
</script>
Implementing Firebase auth on my Vue webpack project.
Google tells me to add the config to my index.html file.
If you do this and to go an view page source it exposes the api key to public. I am confused as to why google would suggest this.
Where should I position the configuration variables so it would be safe. Somebody said that main.js is not a good idea in production.
Where should I do the following in my Vue website.
var config = {
apiKey: "<API_KEY>",
authDomain: "<PROJECT_ID>.firebaseapp.com",
databaseURL: "https://<DATABASE_NAME>.firebaseio.com",
projectId: "<PROJECT_ID>",
storageBucket: "<BUCKET>.appspot.com",
messagingSenderId: "<SENDER_ID>",
};
firebase.initializeApp(config);
You can simply do it in the App.vue
import Firebase from 'firebase'
let config = {
apiKey: "...",
authDomain: "...",
databaseURL: "...",
storageBucket: "...",
messagingSenderId: "..."
};
let app = Firebase.initializeApp(config)
let db = app.database()
let someDataRef = db.ref('dataset')