2017-05-05 142 views
0

我想在ReactJS中使用react-facebook-login package实现Facebook登录按钮。使用提供的代码非常简单。ReactJS Facebook登录使用react-facebook-login包

但是,在用户登录并且有效令牌仍然存在之后,该按钮不会更改并且继续显示“LOGIN WITH FACEBOOK”。我可以在执行console.log看到包括图片ID的accessToken用户ID响应:

ButtonFacebookLogin.js:18

Object {name: "John Doe", picture: Object, id: "101560159xxxxxxx", 
accessToken: "EAAFdByROZC…5tDST3sxnhZASZBZ", userID: "101560159xxxxxxxx"…} 

它应该自行更改,还是应该更改ReactJS脚本中的代码以检查有效登录是否可能?

import React from 'react'; 
import FacebookLogin from 'react-facebook-login'; 

class ButtonFacebookLogin extends React.Component { 
    constructor(props) { 
    super(props); 

    this.responseFacebook = this.responseFacebook.bind(this); 
    this.user = null; 
    }; 

    responseFacebook(response) { 
    console.log(response); 
    this.user = response.name; 
    console.log(this.user); 
    }; 

    componentClicked(response) { 
    console.log(response); 
    }; 

    render() { 
    return (
     <FacebookLogin 
     appId="383760232021913" 
     autoLoad={true} 
     fields="name,email,picture" 
     scope="public_profile,user_friends" 
     onClick={this.componentClicked} 
     callback={this.responseFacebook} 
     /> 
     // just here above the button always looks the same 
    ) 
    } 

对不起,我是新来ReactJS :-),我无法找到这个Facebook的登录按钮封装了大量文档的问题可能听起来很傻。

回答

0

是的,您必须检查它是否已经登录并更改FacebookLogin组件的textButton字段。