React App中的Google身份验证配置问题

时间:2019-11-16 20:40:17

标签: reactjs oauth-2.0

我正在尝试使用Google auth在响应中创建一个登录系统。我的代码在下面,我收到以下错误,请检查

  

组件文件

export default class GoogleAuth extends Component {
    state = {isSignedIn:null}
    componentDidMount(){
        Window.gapi.load('client:auth2', () => {
            Window.gapi.client.init({
                clientId:
                'my-----client-------id',
                scope: 'email'
            }).then(() => {
                this.auth = window.gapi.auth2.getAuthInstance();
                this.setState({isSignedIn:this.auth.isSignedIn.get()})
            })
        })
    }
    renderButton(){
        if(this.state.isSignedIn === null){
            return <div>I dont know if we are signed in </div>
        }else if(this.state.isSignedIn) {
            return <div>yes signed in </div>
        }else{
            return <div>I am not signed in </div>
        }
    }
    render() {
        return (
            <div>
              {this.renderButton}
            </div>
        )
    }
}
  

错误消息

enter image description here

如果有人知道,请告诉问题

1 个答案:

答案 0 :(得分:0)

代替下面的代码(Window函数)

Window.gapi

我应该已经使用过window(Window函数的实例)

 window.gapi