[英]How to create user specific data when user logs in for the first time in realtime firebase database?
[英]Firebase Google Authentication - Check if User Logs in for first time
我在我的網站上使用了也支持Google登錄的注冊/登錄,問題是我在Firestore中創建了一個新的數據文檔,並在其中注冊了uid,但我無法對Google登錄執行此操作,否則會擦除現有條目,因為我只能通過Google登錄,但我需要一種方法來檢查用戶是否已經存在。
googlelogin: function()
{
var provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithPopup(provider).then(function(result) {
// This gives you a Google Access Token. You can use it to access the Google API.
var token = result.credential.accessToken;
// The signed-in user info.
var user = result.user;
db.collection("user").doc(firebase.auth().currentUser.uid).set({
name: firebase.auth().currentUser.email,
favorites: []
})
$('#modal1').modal('close');
// ...
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
// ...
});
},
您可以檢查result.additionalUserInfo.isNewUser
來查看用戶是否是第一次登錄。 signInWithPopup
返回的結果是一個UserCredential
對象: https : UserCredential
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.