Firebase Cloud Messaging - getToken() error in JS SDK - javascript

I am developing an app for KaiOS, a fork of the old Firefox OS, for which apps are based on HTML5 + JS. When compiling and running on device, Firebase Cloud Messaging stops working. I receive an error as follows.
TypeError: 'applicationServerKey' member of
PushSubscriptionOptionsInit could not be converted to any of:
ArrayBufferView, ArrayBuffer.
I've followed the instructions in the Firebase docs here as well as this tutorial on setting up FCM for Progressive Web Apps here. I can confirm I am setting my key before calling getToken, as shown below:
import firebase from "firebase";
const messaging = firebase.messaging();
messaging.usePublicVapidKey("<my-key-from-firebase-settings>");
messaging.getToken().then((currentToken) => {
...
}).catch((err) => {
...
});
I have searched for the above error, but to no avail. Does anyone know what this error means or how to fix it? Running the application in the browser on my development machine, everything works perfectly.
Note: the app is written in Typescript
Firebase SDK Version: 7.12.0

It might not be of help to you but I recently experienced a similar error message in a different environment:
Error: Failed to execute 'subscribe' on 'PushManager': The provided
value is not of type '(ArrayBuffer or ArrayBufferView)'
It was fixed in version 7.13.2 of Firebase:
https://github.com/firebase/firebase-js-sdk/issues/2712
https://firebase.google.com/support/release-notes/js#version_7132_-_april_2_2020

Related

Connecting to Firebase Auth emulator using firebase-js-sdk in Node environment is throwing an error

I am using the 'firebase' client npm package to do client side testing (creating users with email and password), in a node.js environment.
I am following the example given in the docs...
https://firebase.google.com/docs/emulator-suite/connect_firestore#web-version-9
Following that example, my code is as follows...
const firebaseAuth = require('firebase/auth');
const auth = firebaseAuth.getAuth();
firebaseAuth.connectAuthEmulator(auth, 'http://localhost:9099');
And the exception being thrown is...
Uncaught Error FirebaseError: Firebase: Need to provide options, when not being deployed to hosting via source. (app/no-options).

React Native Firebase problem with emulator on physical device

I am programming an app with React Native. To use Firebase in this app, I installed the React Native Firebase npm package. I have set up everything to make requests to Firebase functions and this works smoothly. I am currently trying to set up the Firebase functions emulator to make my dev journey easier. But I can't seem to connect to the emulator.
Client
import functions from '#react-native-firebase/functions';
const DEV = true
if (DEV) {
functions().useEmulator("192.168.x.x", 5001);
}
const sayHelloWorld = () =>{
functions()
.httpsCallable('helloWorld')()
.then(response => {
console.log(response.data)
});
}
sayHelloWorld()
Backend Function
exports.helloWorld = functions.https.onRequest((request, response) => {
response.status(200).send({"data":"Say hello world"});
});
I am using the useEmulator function to switch to the emulator running on port 5001. I am not using useFunctionEmulator as shown in the documentation (https://rnfirebase.io/functions/usage) because it appears to be outdated, but I tried it, and it doesn't work as well. I am using my local IP address for the host because I am running a physical android device. I have no issue running the app, but as soon as I execute the function request nothing happens and after one minute I get the following error message:
Possible Unhandled Promise Rejection (id: 0):
Error: DEADLINE_EXCEEDED
Error: DEADLINE_EXCEEDED
callFirebaseFunctions#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.mmm.sophia&modulesOnly=false&runModule=true:116187:60
_performTransitionSideEffects#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.mmm.sophia&modulesOnly=false&runModule=true:65273:22
_receiveSignal#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.mmm.sophia&modulesOnly=false&runModule=true:65215:45
onResponderRelease#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.mmm.sophia&modulesOnly=false&runModule=true:65055:34
invokeGuardedCallbackProd#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.mmm.sophia&modulesOnly=false&runModule=true:3940:21
invokeGuardedCallback#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.mmm.sophia&modulesOnly=false&runModule=true:4044:42
invokeGuardedCallbackAndCatchFirstError#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.mmm.sophia&modulesOnly=false&runModule=true:4048:36
executeDispatch#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.mmm.sophia&modulesOnly=false&runModule=true:4124:48
executeDispatchesInOrder#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.mmm.sophia&modulesOnly=false&runModule=true:4144:26
executeDispatchesAndRelease#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.mmm.sophia&modulesOnly=false&runModule=true:5493:35
forEach#[native code]
The emulator logs do not show any activity.

How to emulate Firebase authentication without an API key

I'm building an open-source project using Firebase's JS SDK. My goal is to allow contributors to run the project locally using the Firebase emulator so that they don't need any real credentials. The Firebase emulator docs specify that "you can run the emulators without ever creating a Firebase project". That's exactly what I want!
After running firebase init, I wrote up the following code. It triggers a popup that allows users to sign in through GitHub:
import { initializeApp } from "firebase/app";
import { connectAuthEmulator, getAuth, GithubAuthProvider } from "firebase/auth";
const app = initializeApp({
projectId: "demo-project",
});
const auth = getAuth(app);
connectAuthEmulator(auth, "http://localhost:9099");
// When users sign in, we call the following method:
async function signIn() {
const githubAuth = new GithubAuthProvider();
await signInWithPopup(firebaseClientAuth, githubAuth);
}
The code above will trigger the following error:
Uncaught (in promise) FirebaseError: Firebase: Error (auth/invalid-api-key)
In the real world, I would call initializeApp() with an apiKey, but here I just want to emulate authentication. I've also tried not to call initializeApp() at all and call getAuth() without any arguments, but it triggers the same error.
Presumably, an API key requires creating a project, so is it actually possible to run the Firebase auth emulator without creating a Firebase project?
Yes it is.
A demo Firebase project has no real Firebase configuration and no live resources. These projects are usually accessed via codelabs or other tutorials.
Project IDs for demo projects have the demo- prefix.Firebase Docs
Run firebase emulators:start --project demo-[ANYTHING_YOU_WANT]
For example firebase emulators:start --project demo-test-project
is it actually possible to run the Firebase auth emulator without creating a Firebase project?
No, you need to have the emulator connected to a project. You'll notice in the setup instructions you are required to run firebase init to choose your project and the products you want to use in that project.

back4app cloud code functions problem with ES version

I'm using back4app as backend service to deploy my app, developed in React Native ans JS. I'm testing how to use the 'Cloud Code Functions' of back4app right now...
As I'm a beginner in back4app, I found a problem while using their guide. I'm facing this message error: 'async functions' is only available in ES8 (use 'esversion: 8').:
Back4app Side:
import Parse from 'parse/react-native.js';
import AsyncStorage from '#react-native-async-storage/async-storage';
//Initializing the SDK
Parse.setAsyncStorage(AsyncStorage);
//Paste below the Back4App Application ID AND the JavaScript KEY
Parse.initialize('YOUR_APPLICATION_ID_HERE', 'YOUR_JAVASCRIPT_KEY_HERE');
//Point to Back4App Parse API address
Parse.serverURL = 'https://parseapi.back4app.com/';
//This is a hello function and will log a message on the console
Parse.Cloud.define("hello", async (request) => {
console.log("Hello from Cloud Code!");
return "Hello from Cloud Code!";
});
my app:
const helloFunction = await Parse.Cloud.run("hello");
I know the problem comes from the asynchronous function, but I can't find any solution. What am I doing wrong?
When using the cloud code, you do not need to do any kind of initialization as it is already done on the Back4app servers.
So in your main.js file please remove:
The import statements. Lines 2 and 3.
The Parse initialization. The lines 6,8, and 10.
To really answer the question, the error message is a false positive! Probably the online editor is not configured right, so it shows these warnings accidentally...
Just as the guide tells you, you can use the async keyword if you got a running 3.x Parse Server. It should be safe to use this, as per default Parse Server 4.x is used (the server can be changed via App Settings > Server Settings > Manage Parse Server).

react native firebase authentication emulator error message thrown : Error: A network error

I am attempting to use the recently released firebase emulator suite. specifically the authentication emulator.
I have the emulator installed and have created an test user in the auth emulator. as follows:
Within my code I have:
if (firebase.apps.length === 0) {
console.log("setup.js: initializing firebase....")
firebase.initializeApp(firebaseConfig);
firebase.auth().useEmulator('http://localhost:9099/');
} else {
firebase.app(); // if already initialized, use that one
}
to utilized the emulator for authentication. alas I get the following network error:
Has anyone had success utilizing the firebase emulator suite with react native?

Categories