私は、ユーザーがGoogleサインインを使用してサイトにログインできるようにするための基本的なウェブサイトを作成しています。私はこれをファイアベースで行い、それまでのところ成功しています。彼らの文書では、ユーザーはfirebaseリアルタイムデータベースの変数 "auth"に格納され、電子メールとユーザーIDには変数からアクセス可能であることが記載されています。私はドキュメンテーションのすべてのステップを踏んだだけでなく、サンプルファイルをガイドラインとして使用しました。アカウントコントロールパネルには、自分のサイトにログインしているすべてのユーザーとユーザーIDと電子メールアドレスが記載されています。しかし、これはリアルタイムデータベースタブの場合には当てはまりません。ユーザーが何回ログインしてもデータベースは空白のままです。これは、ユーザーの電子メールアドレスにアクセスする必要があるため、大きな問題になりますWebページに表示するなどのこと。次のようにGoogleログインユーザーが消火器データベースに表示されない
私が書いたコードは次のとおりです。
<html>
<head>
<title>SEatAMRS auth test</title>
<script src="https://www.gstatic.com/firebasejs/3.2.0/firebase.js"></script>
<script type="text/javascript">
// Initialize Firebase
var config = {
apiKey: "****************2XqEQSO9Z8vhPF5w",
authDomain: "*********-build.firebaseapp.com",
databaseURL: "https://***********-build.firebaseio.com",
storageBucket: "***********-build.appspot.com",
};
firebase.initializeApp(config);
//Creatse a provider object
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;
// ...
}).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;
// ...
});
//Sign out function
firebase.auth().signOut().then(function() {
// Sign-out successful.
}, function(error) {
// An error happened.
});
</script>
</head>
<body>
<h1>Welcome to the Google Sign in Fucntionality Test!</h1>
</html>
ユーザー情報は自動的にデータベースに格納されません。これは、コードとデータベースのセキュリティ規則で使用できるようになります。情報をデータベースに格納する場合は、独自のコードで行うことができます。 https://stackoverflow.com/questions/14673708/how-do-i-return-a-list-of-users-if-i-use-the-firebase-simple-username-passwordと私たちの遺産のこの例を参照してください。 docs:https://www.firebase.com/docs/web/guide/user-auth.html#section-storing –