I am able to trigger the push notifications, but i get this site has been updated in the background instead of the actual message.
The service worker code :
importScripts('https://www.gstatic.com/firebasejs/3.7.1/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/3.7.1/firebase-messaging.js');
// Initialize Firebase
var config = {
apiKey: "**************",
authDomain: "push-notifications-240e1.firebaseapp.com",
databaseURL: "https://push-notifications-240e1.firebaseio.com",
projectId: "push-notifications-240e1",
storageBucket: "push-notifications-240e1.appspot.com",
messagingSenderId: "********"
};
firebase.initializeApp(config);
i have fixed the issue, The service worker file had been cached. I will close this question now. I fixed it by adding the file in cache control.
Related
I'm making an app that writes a waiting list in the firebase realtime databse, but when I try to run this simple bit of code, I get this error (Note- I'm running this on web):
class FirebaseMethods {
FirebaseDatabase database = FirebaseDatabase.instance;
void createPartyWaiting(String partyCode, String partyHostName) async {
partyCode = partyCode.trim();
DataSnapshot data = await database.ref("e").get();
print(data.value);
}
}
and i'm calling it as-
await FirebaseMethods().createPartyWaiting("PartyCode123", "Adam");
But when I call it, I get this error-
Error: FIREBASE FATAL ERROR: Cannot parse Firebase url. Please use https://<YOUR FIREBASE>.firebaseio.com
at Re (https://www.gstatic.com/firebasejs/8.10.0/firebase-database.js:1:22344)
at Ws (https://www.gstatic.com/firebasejs/8.10.0/firebase-database.js:1:148180)
at au (https://www.gstatic.com/firebasejs/8.10.0/firebase-database.js:1:166314)
at K.xu.INTERNAL.registerComponent.Y.setServiceProps.Reference [as instanceFactory] (https://www.gstatic.com/firebasejs/8.10.0/firebase-database.js:1:187315)
I'm initializing the web like this (I've censored the actual values)-
void main() async {
WidgetsFlutterBinding.ensureInitialized();
if (kIsWeb) {
Firebase.initializeApp(
options: const FirebaseOptions(
apiKey: "apikey",
authDomain: "authDomain",
projectId: "projectId",
storageBucket: "storageBucket",
messagingSenderId: "messagingSenderId",
appId: "appId"));
}
runApp(const MyApp());
}
I've also found out that there's this optional arguement to the initilaziation method-
But after adding my databaseUrl here, I got this error-
Error: [core/duplicate-app] A Firebase App named "[DEFAULT]" already exists
at Object.throw_ [as throw] (http://localhost:53659/dart_sdk.js:5063:11)
at firebase_core_web.FirebaseCoreWeb.new.initializeApp (http://localhost:53659/packages/firebase_core_web/firebase_core_web.dart.lib.js:248:27)
What am I doing wrong, and how do I fix this? Thanks!
For anyone who has used $ flutterfire configure to configure firebase to your flutter project as shown in here before adding Realtime Database, you will have to run the command again to reconfigure your project or add "databaseURL" to the FirebaseOptions in your lib/firebase_options.dart.
Your lib/firebase_options.dart should look something like this:
// inside lib/firebase_options.dart
// ...
static const FirebaseOptions web = FirebaseOptions(
apiKey: '...',
appId: '...',
messagingSenderId: '...',
projectId: 'project-id',
authDomain: 'project-id.firebaseapp.com',
databaseURL: 'https://your-database-id.firebasedatabase.app', // IMPORTANT!
storageBucket: 'project-id.appspot.com',
measurementId: '...',
);
// ...
Since you're configuring your Firebase project (for web) by passing the configuration data to Firebase.initializeApp, you should also include the URL for your database there:
Firebase.initializeApp(
options: const FirebaseOptions(
apiKey: "apikey",
authDomain: "authDomain",
databaseURL: "the URL for your database", // 👈
projectId: "projectId",
storageBucket: "storageBucket",
messagingSenderId: "messagingSenderId",
appId: "appId"));
You can find this URL in your browser by going to the Realtime Database panel in the Firebase console:
I'm not sure why the databaseURL doesn't show in your auto-complete though, as I have it in all of my Dart configs (most of which are generated by the FlutterFire CLI).
If entering the databaseURL manually gives an error message, I recommend checking if you're on the latest version of the libraries (although I don't recall this ever not being present).
I recreated the flutter and firebase project with a new app id, and it worked.
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>
I'm new to React Native and Firebase coding. I'd like to skip the login process if the user logged in successfully last time. According to Firebase doc, firebase.auth.Auth.Persistence.LOCAL can persist the authentication state even the activity is destroyed. The problem is how can I check the local persisted authentication state when the app initializes?
I managed to use AsyncStorage to achieve the goal, but firebase.auth.Auth.Persistence.LOCAL is supposed to be the simpler approach, but I can't figure it out.
Init codes:
<pre>
componentWillMount() {
const firebaseConfig = {
apiKey: "xxxxxxxxxx",
authDomain: "xxxxx.firebaseapp.com",
databaseURL: "https://xxxx.firebaseio.com",
projectId: "xxxxxx",
storageBucket: "xxxxx.appspot.com",
messagingSenderId: "xxxxxxx"
};
if (!firebase.apps.length) {
console.log("call firebase init");
firebase.initializeApp(firebaseConfig);
console.log(firebase.app().options);
}
}
</pre>
Firebase as release the functions V1.0 and it means a lot of changes in the way to write the code.
I would like to do the migration, I understood all the changes, except the one about the admin.initializeApp
Firebase says that
firebase-admin is now initialized without any parameters within the
Cloud Functions runtime
But I need to access another project database from my actual project.
Until now I was doing it as follows :
/* Initialize the SecondApp service acccount */
var serviceAccount = require("./service-account.json");
/* Initialize SecondApp with the serviceAccount credentials */
var SecondApp = admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
apiKey: "**************",
authDomain: "****************",
databaseURL: "****************",
projectId: "****************",
storageBucket: "****************",
messagingSenderId: "****************"},"SecondApp");
What will be the new way of doing it ?
I read the documentation and tried to implement in HTML page but it did not work.
I created the FCM project and select the cloud messaging and select the web part. They provided the following file:
<script src="https://www.gstatic.com/firebasejs/4.1.2/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "BIzaSyCODqtGdk9xNYU4ifeWiUvnRyrWA_N6np0",
authDomain: "checking-22492.firebaseapp.com",
databaseURL: "https://testings-22492.firebaseio.com",
projectId: "checking-22492",
storageBucket: "checkingwebdemo-22492.appspot.com",
messagingSenderId: "648493233490"
};
firebase.initializeApp(config);
</script>
I have already integrated it into iOS and Android, Please suggest how it will work in the web application.