微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

react-google-login抛出错误“用户关闭了pop_up”

如何解决react-google-login抛出错误“用户关闭了pop_up”

我正在使用react-google-login在我的项目中使用google登录,但是当我使用chrome浏览器时,它抛出“ pop_up被用户关闭错误,并且弹出窗口被关闭。我尝试清除缓存,但是我想要对此的永久解决方案。 下面是我的代码


async googleLogin(res) {
    
      const {social_login_user} = this.state
      let postData;
      if (res.error == undefined && res.profileObj.imageUrl) {
        let email= res.profileObj.email
        let img_url = res.profileObj.imageUrl
        let response_img = await axios.get(img_url,{
          responseType: 'arraybuffer'
        })
        const base64 = "data:image/jpeg;base64,"+new Buffer(response_img.data).toString('base64')
        var random_number = Math.floor(1000 + Math.random() * 9000);
        let generated_username = email.substring(0,email.lastIndexOf("@")).substring(0,12)+random_number
        postData = {
          name: res.profileObj.name,email: email,image:res.profileObj.imageUrl,username: generated_username,type:'google',image_base64: base64
        }
          
          this.setState({
            social_login_user: {
              ...social_login_user,...postData,custom_username:'',profile_image:"social_image",profile_username:"social_username"},image_warning:''
          },()=>{
            axios({
              url: API_URL+"user/checkuserexistance",method:"post",data:{
                email:email
              }
            }).then(response=>{
              if(response.data.status==200){
                this.setState({
                  show_social_login_Box: !response.data.user_exist
                })
                if(response.data.user_exist){
                  this.props.dispatch(loginWithSocialAccount(this.state.social_login_user))
                }
              }
              //console.log(response)
            }).catch(error=>{

            })
          })
       }  
   }
          
 <GoogleLogin
 clientId={googleClientId}
 buttonText="Login with Google"
 onSuccess={ this.googleLogin}
 onFailure={ this.googleLogin}
                            
 />

如果有人有任何建议或可以帮助我解决这个问题,我将非常感激。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。