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=".9.0/firebase-app.js"></script>
<script src=".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
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./firebasejs/5.9.0/firebase-app.js"></script>
<script src="https://www.gstatic./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
Share Improve this question edited Dec 16, 2019 at 22:25 Dharman♦ 33.5k27 gold badges101 silver badges148 bronze badges asked Mar 20, 2019 at 21:46 Andrey SoleraAndrey Solera 2,4023 gold badges29 silver badges55 bronze badges 4- I think you cant wix./code/home/forum/munity-discussion/… maybe you installed the packages on your puter – cutiko Commented Mar 21, 2019 at 0:03
- that's an old answer... new ones say that is actually is possible, however is not documented properly – Andrey Solera Commented Mar 21, 2019 at 4:07
- Can you provide the link? And also explain further what do you mean with "I installed the firebase and firestore node packages successfully", please – cutiko Commented Mar 21, 2019 at 14:16
- question has been updated – Andrey Solera Commented Mar 21, 2019 at 18:54
3 Answers
Reset to default 2 +100There 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./corvid/forum/main/ment/5c5a4ffff7055001e2d15cd4
This might be helpful "The short answer is no - Wix Code only supports its internally used database."
more details https://www.wix./corvid/forum/munity-discussion/is-there-a-way-to-connect-to-firebase-database
The accepted solution is problematic, and hacky equates to fragile. So when it breaks, you may not be aware of it for some time or it may break often. The best solution is to use wix and
Using wix-router and wix-fetch you can write code that pulls information from ining requests for the profile page, queries an external database to retrieve the information for the page, and then injects that data into the profile page
https://css-tricks./wix-code-database-data-modeling/