[英]Using a web page, after sign up on Firebase, with Facebook
I have a small web site where users can sign in on Firebase, using email and password. 我有一个小型网站,用户可以在其中使用电子邮件和密码在Firebase上登录。
I uses this code: 我使用以下代码:
<script>
function SignUpWithMailPSW(email,pswRdmSeq) {
....
firebase.auth().createUserWithEmailAndPassword(email, pswRdmSeq).then(function(user) {
....
}
... useful things irrelevant to the question.
}
</script>
Now users can also sign in using Facebook. 现在,用户还可以使用Facebook登录。
To get started I found this document . 首先,我找到了此文档 。 And to experiment I did something based on what I read, just a small test page.
为了进行实验,我根据阅读的内容做了一些操作,只是一个很小的测试页。 Here is the code:
这是代码:
<HTML>
<HEAD>
<META HTTP-EQUIV="content-type" CONTENT="text/html; CHARSET=UTF-8">
<script src="https://www.gstatic.com/firebasejs/6.3.5/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/6.3.5/firebase-auth.js"></script>
</HEAD>
<BODY>
<script>
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey: "ABCDEF-APIKEY-12345",
authDomain: "myapp.firebaseapp.com",
databaseURL: "https://myapp.firebaseio.com",
projectId: "myapp",
storageBucket: "myapp.appspot.com",
messagingSenderId: "123456789",
appId: "1:987654321:web:xy2122k98xyxy8988"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
</script>
<b>TEST ONLY PAGE !!!</b>
<script>
var provider = new firebase.auth.FacebookAuthProvider();
function SignUpWithFB() {
// var provider = new firebase.auth.FacebookAuthProvider();
firebase.auth().signInWithPopup(provider).then(function(result) {
// This gives you a Facebook Access Token. You can use it to access the Facebook 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;
// ...
});
}
SignUpWithFB();
</script>
<b>TEST ONLY PAGE !!!</b>
</BODY>
</HTML>
At this point it is starting to work. 此时,它开始工作。
But I would like to know how to make use of the result (and result.credential ) parameter that we get in the call back function (or promise?): 但是我想知道如何利用我们在回调函数(或promise?)中得到的result (和result.credential )参数:
firebase.auth().signInWithPopup(provider).then(function(result) {});
I did not find anything significant about this result variable (type, fields, use, ..etc..) searching the net. 我没有发现关于此结果变量(网络,类型,字段,用途等)的任何重要信息。
Some hints would be very useful. 一些提示将非常有用。
The result variable which you are getting in the then part of the promise , is an object (type) holding all the information about the user. 您在promise的随后部分中得到的结果变量是一个对象 (类型),包含有关用户的所有信息。 And contains a lot of properties on itself, using which you can get all of these data very easily.
并且本身包含许多属性,使用它们可以非常轻松地获取所有这些数据。
Naming a few important ones 命名一些重要的
Note : To list and check all these property , try outputting it in console console.log(result);
注意:要列出并检查所有这些属性,请尝试在控制台
console.log(result);
输出它console.log(result);
The signInWithPopup
method is declared as: signInWithPopup
方法声明为:
signInWithPopup(provider: AuthProvider): Promise<UserCredential>
So it returns Promise<UserCredential>
. 因此它返回
Promise<UserCredential>
。 This means that in your then
callback you get a UserCredential
object , which is declared as: 这意味着在
then
回调中,您将获得一个UserCredential
对象 ,该对象声明为:
Optional additionalUserInfo?: AdditionalUserInfo | null credential: AuthCredential | null Optional operationType?: string | null user: User | null
So it has a user
and a credential
property, and may also have additionalUserInfo
and operationType
. 因此,它具有
user
和credential
属性,并且可能还具有additionalUserInfo
和operationType
。
For more information on each of these, keep following the links in the reference documentation. 有关这些信息的更多信息,请继续关注参考文档中的链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.