Search code examples
javascriptfirebasevelo

How to connect Firebase with Wix


The code that I'm using is the following one:

import firebase from "firebase"
import firestore from "firestore"

export function base() {
    // Initialize Firebase
    var config = {
        apiKey: "apiExample",
        authDomain: "authDomaninExample",
        databaseURL: "databaseUrlExample",
        projectId: "projectIdExample",
        storageBucket: "storageBucketExample",
        messagingSenderId: "000000000"
    };
    firebase.initializeApp(config)

    var db = firebase.firestore(); // This line breaks the code

    db.settings({ timestampsInSnapshots: true })

    db.collection("Users")
        .add({
            test: "Test"
        }).then(function (docRef) {
            console.log("Document written")
        }).catch(function (error) {
            console.log("Error is: " + error)
        });
}

The base() function is called by clicking a button, however the code is not working, and no console logs are shown.

PS: I installed the Firebase and Firestore node packages successfully according to the Wix page

The error I get is the following:

TypeError: firebase.database is not a function

The solution that works is the following:

<script src="https://www.gstatic.com/firebasejs/5.9.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.9.0/firebase-database.js"></script>
<script>
  // Initialize Firebase
  var config = {
    apiKey: "apiExample",
    authDomain: "authDomaninExample",
    databaseURL: "databaseUrlExample",
    projectId: "projectIdExample",
    storageBucket: "storageBucketExample",
    messagingSenderId: "000000000"
  };
  firebase.initializeApp(config)

  var db = firebase.firestore(); // This line breaks the code

  db.settings({ timestampsInSnapshots: true })

  db.collection("Users")
    .add({
      test: "Test"
    }).then(function (docRef) {
    console.log("Document written")
  }).catch(function (error) {
    console.log("Error is: " + error)
  });
</script>

However I don't want to use scripts since I prefer to use typescript


Solution

  • There seems to be a hacky solution suggested by one of the users in the wix forums.

    Here is the link to it, maybe this will help you.

    https://www.wix.com/corvid/forum/main/comment/5c5a4ffff7055001e2d15cd4