简体   繁体   English

在Firebase上注册后,通过Facebook使用网页

[英]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 命名一些重要的

  • displayName : Gives you User's display name displayName :为您提供用户的显示名称
  • email : Gives you the user's email ID email :为您提供用户的电子邮件ID
  • emailVerified : Tells you whether the email-ID is verified or not emailVerified :告诉您是否已验证电子邮件ID
  • metadata : Itself a object containing info such as LastSignInTime and creationTime 元数据 :本身是包含诸如LastSignInTime和creationTime之类的信息的对象
  • photoURL : A URL to the picture of user, the current one. photoURL :指向用户图片的URL,即当前的URL。
  • uid : (very useful) Unique ID associated with each user, which will let you do many authentication ahead. uid :(非常有用)与每个用户关联的唯一ID,这将使您提前进行许多身份验证。

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 . 因此,它具有usercredential属性,并且可能还具有additionalUserInfooperationType

For more information on each of these, keep following the links in the reference documentation. 有关这些信息的更多信息,请继续关注参考文档中的链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在注册时存储用户名仅在页面刷新后显示 (Firebase) - Storing a username on sign up only displays after page refresh (Firebase) 使用谷歌登录后重定向到另一个页面 - Firebase Web - Redirecting to another page after sign in with google - Firebase Web 在 firebase 中注册后用户数组未定义 - User Array is undefined after sign up in firebase firebase web 注册与 google 仅在第二次点击后才有效? - firebase web sign up with google only works after clicking the second time? Firebase - onAuthStateChanged() 在登录和注册后触发 - Firebase - onAuthStateChanged() fires both after sign in and sign up 使用Facebook注册-Angular 4 Typescript - Sign Up using Facebook - Angular 4 Typescript Firebase身份验证 - 用户在Firebase注册和重定向后未登录 - Firebase Auth - User not logged in after Firebase sign up and redirect 页面刷新后,注册按钮消失 - sign up button disappear after page refreshing Firebase / React:onAuthStateChanged()是在注册函数的时间之前还是之后触发的? - Firebase/React: is onAuthStateChanged() triggered before or after the then of a sign up function? 密码注册后 Firebase 云函数未经身份验证的错误 - Firebase Cloud Function Unauthenticated Error After Password Sign-Up
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM