What benefit does linking Firebase web app to Firebase Hosting site brings? - firebase

What for should I link the web app to the Firebase Hosting site in the console? What are the benefits and effects?
The difference between the two is covered here: Whats the difference between firebase web app and firebase hosting.
The linking is mentioned in the documentation https://firebase.google.com/docs/web/setup#register-app, but the rationale and consequences are not explained.

The Firebase support documentation says:
You may need to link your web app to your Hosting site in the Project settings if you chose not to set up Hosting when you registered your web app with your Firebase project.
If you're using Firebase Hosting for your web app, you can use the reserved Hosting URLs to add Firebase SDKs and manage your Firebase configuration for your app.
In short, if you're using those special Hosting URLs that begin with __, in particular, /__/firebase/init.json, it helps to have linked your app to Hosting so that the configuration is complete. By my recollection, the config will then have a correct FCM config in this case.

You can configure partial import of the Firebase JavaScript SDK and only load the Firebase products that you need. If you're using a bundler (like Browserify or webpack), you can import individual Firebase products when you need them.
Note: You can use this option even if you use Firebase Hosting, but make sure to add your Firebase config object before initializing Firebase.
Install the Firebase JavaScript SDK:
a. If you don't already have a package.json file, create one by running the following command from the root of your JavaScript project:
npm init
b. Install the firebase npm package and save it to your package.json file by running:
npm install --save firebase
To include only specific Firebase products (like Authentication and Cloud Firestore), import Firebase modules:
// Firebase App (the core Firebase SDK) is always required and must be
listed first
import firebase from "firebase/app";
// If you are using v7 or any earlier version of the JS SDK, you should
import firebase using namespace import
// import * as firebase from "firebase/app"
// If you enabled Analytics in your project, add the Firebase SDK for
Analytics
import "firebase/analytics";
// Add the Firebase products that you want to use
import "firebase/auth";
import "firebase/firestore";
Initialize Firebase in your app:
// TODO: Replace the following with your app's Firebase project
configuration
// For Firebase JavaScript SDK v7.20.0 and later, measurementId is an
optional field
const firebaseConfig = {
// ...
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);

Related

Install Firebase SDK v9 on Google App Script?

I am trying to use Firebase SDK on my Google App Script app.
The documentation says it needs installing npm install firebase which is not possible via Google App Script.
So the following step would be:
// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
import { getAnalytics } from "firebase/analytics";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: "***",
authDomain: "myapp.firebaseapp.com",
databaseURL: "https://myapp-default-rtdb.europe-west1.firebasedatabase.app",
projectId: "myappurl",
storageBucket: "myappurl.appspot.com",
messagingSenderId: "267227785525",
appId: "***",
measurementId: "G-K5CP51FRXR"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
But i get the error:
SyntaxError: Cannot use import statement outside a module linea:
It looks like i am not declaring it as a module.
I have checked for tutorials and help but only find the how-to for Node.js, Google Script is not talked about.
Note: I have installed 'FirebaseApp' library.
Anyone knows how to do what i need? Is that even possible to use SDK v9 on GAS?
While Google Apps Script and Node.js uses JavaScript as programming language, Node.js has several features that aren't included in Google Apps Script, one of them is the the npm packages handling.
One option might be to use the npm package "as a client-side library". Please start by reading https://developers.google.com/apps-script/guides/web, then checkout Use npm package on client side.
Some client-side libraries might work as server side JavaScript. Nowadays Google Apps Script has two runtimes, but one, Rhino, depends on the old Google Apps Script IDE that will be retired soon. To learn about the new runtime, V8, please read https://developers.google.com/apps-script/guides/v8-runtime.
Some npm packages have being "converted" into Google Apps Script libraries. You might try to find on by searching this site, a service like GitHub, etc. Another option is to ask for a software recommendation on https://softwarerecs.stackexchange.com.
Another option is to use the Firebase REST API directly in Google Apps Script by using the Url Fetch Service.
Related
Using an imported module inside Google App Script
How to integrate Firebase into Google Apps Script without using (deprecated) database secret
Cannot add Firebase library to Apps Script
Syntax error: SyntaxError: Cannot use import statement outside a module line: 1 file: Code.gs

firestore is not working with React Native Expo

I installed firebase with react native expo using expo add firebase, then
I created a file (firebase.tsx) and added the Firebase configuration and initialized the app like in this screenshot with correct values].
I have added the google-services.json and
GoogleService-info.plist to the root of my expo project like the documentation say and i am importing firebase in my api service like this import Firebase from './../../../firebase'.
In my register function I call the firebase create user function
const response = await Firebase.auth().createUserWithEmailAndPassword(values.email.value, values.password.value)
The response is never returned, and if I use . then nothing happens either.
If I log firebase.auth I get an object with my API key and app name, etc. so Firebase is installed, but whenever I call the database for sign in or to access a collection nothing happens.
This is my package.json.
This is my app.json.
I added bundleIdentifier and googleServicesFile to iOS and package and googleServicesFile for Android.
currently Firebase seems not to be working in expo if you are using the android configuration. I have tried the web configuration and it has worked for me. Here is the youtube tutorial for it. Watch from 38:20 to set up.

Firebase and Google Analytics - missing measurementId?

I have a few Firebase projects on which I use Firestore and Firebase Storage.
I want to start using Google Analytics and I see this page with all the instructions. The key setting being the parameter "measurementId".
So, following the instructions, I go to my project settings and find the config snippet but unlike in the instructions it does NOT contain this parameter...
How do I generate it?
The solution came from Firebase support, my project needed to be "relinked" to Google Analytics.
Relink your Firebase project to a Mobile App property
If you had
previously linked your Firebase project with your Analytics account
but are no longer able to locate your Firebase project in Analytics:
Open your Firebase project.
Open Project settings > Integrations.
Click the Analytics card to link Analytics to your project.
More details here
I experienced this also. It seems there is a bug in the website. Set up Firebase CLI and run the following command.
firebase --project <project-name> apps:sdkconfig
It should output something like the following:
? Select the app to get the configuration data: Web - 1:686396208177:web:5119a766dc890b7d671110 (WEB)
✔ Downloading configuration data of your Firebase WEB app
// Copy and paste this into your JavaScript code to initialize the Firebase SDK.
// You will also need to load the Firebase SDK.
// See https://firebase.google.com/docs/web/setup for more details.
firebase.initializeApp({
// ... snip ...
"measurementId": "redacted"
});
It includes measurementId.

firebase: can't find variable IDBIndex

I'm developing an app with react-native (v0.60) and I need push notifications. I decided to use firebase as service but I have an error during initialisation.
Code:
import {AppRegistry} from 'react-native';
import Config from 'react-native-config'
import * as firebase from 'firebase/app'
import '#firebase/messaging'
import firebaseConfig from 'App/src/firebase.config'
import App from './App';
import {name as appName} from './app.json';
firebase.initializeApp(firebaseConfig)
const messaging = firebase.messaging()
messaging.usePublicVapidKey(Config.FIREBASE_KEY_PAIR)
AppRegistry.registerComponent(appName, () => App);
The problem is that I get the error:
ReferenceError: Can't find variable: IDBIndex
How can I fix this?
firebase only supports Authentication, Firestore & Realtime databases, Storage, and Functions on React Native. Other modules like Analytics are not supported through the Firebase JS SDK, but you can use expo-firebase-analytics for that. If you'd like access to the full suite of native firebase tools
please remove firebase.analytics();
It's because you have enabled Google Analytics for your app. Disable Analytics from the Firebase settings and again copy the Firebase file data from Firebase and replace it with the old firebase.js file in the project.
I would advise to use the React Native Firebase wrapper instead. As they say:
Although some features from the Firebase Web SDK will generally work with React Native, it is mainly built for the web and as such has a limited compatible feature set. In contrast we use the Firebase Native SDKs - this allows us to provide APIs to a vast majority of Firebase products and services.
please remove firebase.analytics(); form where ?

Firebase Admin Node.js SDK doesn't have firebase.firestore.FieldValue.increment. Should I use Firebase JavaScript SDK (Client)?

My app engine is using Firebase Admin Node.js SDK to use Firebase.firestore (and other products). I want to use firebase.firestore.FieldValue.increment to implement a counter.
But it doesn't seem Firebase Admin Node.js SDK has firebase.firestore.FieldValue.increment.
Should I use Firebase Javascript Client SDK for it? If so, I have to use both Firebase Javascript Client SDK and Firebase Admin Node.js SDK. Is it OK?
I am using Node.js 8 and "firebase-admin": "^7.0.0".
admin.firestore.FieldValue is just an alias to this type defined in the #google-cloud/firestore package: https://cloud.google.com/nodejs/docs/reference/firestore/1.3.x/FieldValue
So anything available in that type is readily available in admin.firestore.FieldValue as well. That includes increment(). The documentation is just out of date.

Resources