1

在以下片段中,我尝试使用 npm react-google-login 将 google oauth 实现到我的 web 应用程序中。当我尝试登录时,弹出窗口出现,我选择了我的一个帐户,然后出现一个加载圆圈并且弹出窗口关闭。(不确定这是否是崩溃)。但是,我的 googleSuccess 函数似乎没有被调用,因为我记录的所有内容都没有出现在控制台中。过早关闭弹出窗口会在 onFailure 中记录 googleError。有谁知道为什么我的 onSuccess 回调可能不会触发?

 const googleSuccess = async (res) => {
    console.log("In googlesuccess");
    try {
        console.log("G sign in success", res);
    } catch (err) {
        console.error(err);
    }
        
};
const googleError = (err) => {
    console.error('Google sign in failed.', err);
};
<GoogleLogin
        clientId= //removed, but my client id is here in my actual code
        render={(renderProps) => (
            <Button className={classes.googleButton} color="primary" fullWidth onClick={renderProps.onClick} disabled={renderProps.disabled} startIcon={<Icon />} variant="contained">
                Google Sign In
            </Button>
        )}
        onSuccess={googleSuccess}
        onFailure={googleError}
        cookiePolicy="single_host_origin"
/>
4

1 回答 1

0

我面临同样的问题。

这是我的代码

<GoogleLogin
            clientId="id"
            render={(renderProps) => (
              <Button
                fullWidth
                variant="contained"
                color="primary"
                onClick={renderProps.onClick}
                disabled={renderProps.disabled}
                startIcon={<Icon />}
                className={classes.googleButton}
                onSuccess={googleSuccess}
                onFailure={googleFailure}
                cookiePolicy={"single_host_origin"}
              >
                Google Sign In
              </Button>
            )}
          />          

                                                                                                    
于 2022-02-05T17:05:52.037 回答