我正在编写一个包含firesore的脚本。当我在代码中正确定义凭据时,它工作正常,但是如何使用userdata对其进行初始化? 我添加了一些输入,并尝试从那里获取凭据,但是它出现了诸如“未定义数据库”或“已存在名为默认名称的Firebase应用程序”之类的任何错误。
//define var for credentials
var config = {
apiKey: "",
authDomain: "",
databaseURL: "",
projectId: "",
storageBucket: "",
messagingSenderId: ""
}
//some vars go here
//some init functions go here like adding buttons etc
// setting up the connection with user input
$("button[name='submit-config']").on("click", function(){
config.apiKey = $( "input[name='apiKey']" ).val();
config.authDomain = $( "input[name='authDomain']" ).val();
config.databaseURL = $( "input[name='databaseURL']" ).val();
config.projectId = $( "input[name='projectId']" ).val();
config.storageBucket = $( "input[name='storageBucket']" ).val();
config.messagingSenderId = $( "input[name='messagingSenderId']").val();
firebase.initializeApp(config);
const db = firebase.firestore();
db.settings({ timestampsInSnapshots: true });
//get data from the base
});
我在做什么错了?