React Google Login

て烟熏妆下的殇ゞ 提交于 2020-03-23 08:07:08

问题


I am using react-google-login (https://www.npmjs.com/package/react-google-login) tool to login to provide Google login functionality for my application. Following the manual on page I ended up using following code.

<GoogleLogin
   clientId="xxx.apps.googleusercontent.com"
   onSuccess={this.responseGoogle.bind(this)}
   onFailure={this.responseGoogle.bind(this)}
   tag={'span'}
   className={"google-button-wrapper"}
   >
   <Button id={'google-button'} basic
      color='google plus'>
      <Icon name='google plus'/>
      Google Plus
   </Button>
</GoogleLogin>

The problem is that the login action is triggered even without clicking the button. This happens after refresh page.

I found following suspicious scenarios:

Refresh page -> open Login page = Triggered

Refresh page -> open Login page -> Open different site -> Login again = Triggered first time, second time no trigger.

Refresh page -> open Login page -> open Registration Page = Trigger on Login page, not trigger on Register page even if there is same snipped of code.

I am using React v ^16.3.2, Any ideas?


回答1:


try to use arrow functions inside onSuccess and onFailure and don't bind them here. It is better practice to bind functions on constructor



来源:https://stackoverflow.com/questions/51984016/react-google-login

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!