I am attempting to create a Push Notification Web tool for my iOS app. For now, all I am trying to do is query my Firebase Realtime database and console.log the values.
My hope was to be able to create an HTML doc, and integrate firebase using CDN and house all of that, along with my query in tags.
When I do this, I am getting an error in console that says "Uncaught ReferenceError: firebase is not defined"
Any idea what I am missing or why I am getting this error?
Here is what I have in my script tags:
<!DOCTYPE html><html lang="en">
<head></head>
<body>
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.4/firebase-app.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.6.4/firebase-analytics.js";
// 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: "xxxx",
authDomain: "xxx",
databaseURL: "xxx",
projectId: "xxx",
storageBucket: "xxx",
messagingSenderId: "xxx",
appId: "xxx",
measurementId: "G-xxx"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
import { getDatabase } from "https://www.gstatic.com/firebasejs/9.6.4/firebase-database.js";
const database = getDatabase();
</script>
<script>
//query database for ExpononentPushToken Values//
const dbRef = firebase.database().ref();
dbRef.child("push_token").child(userId).get().then((snapshot) => {
if (snapshot.exists()) {
console.log(snapshot.val());
} else {
console.log("No data available");
}
}).catch((error) => {
console.error(error);
});
</script>
</body>
</html>