我正在尝试在用户注册时设置点,但是我不知道该怎么办,因为我搜索的所有内容都无处可寻。
我曾尝试搜索Google和Firebase文档,但未找到任何内容!
Index.html
这是我用来使用户登录或注册的代码:
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://www.gstatic.com/firebasejs/6.2.3/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/6.2.3/firebase-auth.js"></script>
<!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#config-web-app -->
<script>
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey:
authDomain:
databaseURL:
projectId:
storageBucket:
messagingSenderId:
appId:
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
</script>
<script src="https://cdn.firebase.com/libs/firebaseui/4.0.0/firebaseui.js"></script>
<link type="text/css" rel="stylesheet" href="https://cdn.firebase.com/libs/firebaseui/4.0.0/firebaseui.css" />
<script type="text/javascript">
// FirebaseUI config.
var uiConfig = {
signInSuccessUrl: 'index.html',signInOptions: [
// Leave the lines as is for the providers you want to offer your users.
firebase.auth.GoogleAuthProvider.PROVIDER_ID,//firebase.auth.FacebookAuthProvider.PROVIDER_ID,// firebase.auth.TwitterauthProvider.PROVIDER_ID,// firebase.auth.GithubAuthProvider.PROVIDER_ID,firebase.auth.EmailAuthProvider.PROVIDER_ID,// firebase.auth.PhoneAuthProvider.PROVIDER_ID,firebaseui.auth.AnonymousAuthProvider.PROVIDER_ID
],// tosUrl and privacyPolicyUrl accept either url string or a callback
// function.
// Terms of service url/callback.
tosUrl: '<your-tos-url>',// Privacy policy url/callback.
privacyPolicyUrl: function () {
window.location.assign('<your-privacy-policy-url>');
}
};
// Initialize the FirebaseUI Widget using Firebase.
var ui = new firebaseui.auth.AuthUI(firebase.auth());
// The start method will wait until the DOM is loaded.
ui.start('#firebaseui-auth-container',uiConfig);
</script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Login</title>
</head>
<body>
<!-- The surrounding HTML is left untouched by FirebaseUI.
Your app may use that space for branding,controls and other customizations.-->
<div id="firebaseui-auth-container"></div>
</body>
</html>
index.js
这是我要用来使保存数据正常工作的代码!
var db = firebase.firestore();
db.collection("users").set({
points: 0,CompletedLevels: 0
})
.then(function (docRef) {
console.log("Document written with ID: ",docRef.id);
})
.catch(function (error) {
console.error("Error adding document: ",error);
});
async function savePoints() {
let docRef = await db.collection("users").add({
points: 0,})
}
async function saveCompletedLevels() {
let docRef = await db.collection("users").add({
CompletedLevels: 0
})
}
login.html
这是我获得firestore API的代码!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script src="https://www.gstatic.com/firebasejs/7.2.3/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.2.3/firebase-auth.js"></script>
<!-- <script src="https://www.gstatic.com/firebasejs/6.2.3/firebase-database.js"></script> -->
<script src="https://www.gstatic.com/firebasejs/7.2.3/firebase-firestore.js"></script>
<!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#config-web-app -->
<script>
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey:
authDomain:
databaseURL:
projectId:
storageBucket:
messagingSenderId:
appId:
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
</script>
<script src="index.js"></script>
</body>
<head> <button type="button" onclick="SavePoints()">Click Me!</button></head>
</html>