Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/478.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如果没有全局onSignIn功能,如何成功触发google onSignIn数据?_Javascript_Html_Authentication_Google Signin - Fatal编程技术网

Javascript 如果没有全局onSignIn功能,如何成功触发google onSignIn数据?

Javascript 如果没有全局onSignIn功能,如何成功触发google onSignIn数据?,javascript,html,authentication,google-signin,Javascript,Html,Authentication,Google Signin,玩过谷歌标志后。我想通过将代码放在另一个文件中并可能重命名它们来稍微清理一下代码 但是,如果我将onSignIn函数作为对象的属性,那么成功时的数据将不起作用 我想试试这种东西 const google_auth = {}; google_auth.id_token = null; google_auth.onSignIn = (googleUser) => { const profile = googleUser.getBasicProfile(); const id_

玩过谷歌标志后。我想通过将代码放在另一个文件中并可能重命名它们来稍微清理一下代码

但是,如果我将
onSignIn
函数作为对象的属性,那么成功时的
数据将不起作用

我想试试这种东西

const google_auth = {};
google_auth.id_token = null;

google_auth.onSignIn = (googleUser) => {
    const profile = googleUser.getBasicProfile();
    const id_token = google_auth.id_token = googleUser.getAuthResponse().id_token;

    console.log(profile, 'profile');
    console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
    console.log('ID token: ' + id_token);
    console.log('Name: ' + profile.getName());
    console.log('Image URL: ' + profile.getImageUrl());
    console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
    console.log(id_token.split('.'), 'id_token split');
};
然后我尝试了html

但不会调用该函数。如果我只使用原始代码,例如

const google_auth = {};
google_auth.id_token = null;

function onSignIn(googleUser) {
    const profile = googleUser.getBasicProfile();
    const id_token = google_auth.id_token = googleUser.getAuthResponse().id_token;

    console.log(profile, 'profile');
    console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
    console.log('ID token: ' + id_token);
    console.log('Name: ' + profile.getName());
    console.log('Image URL: ' + profile.getImageUrl());
    console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
    console.log(id_token.split('.'), 'id_token split');
};

这非常有效,我试着在谷歌上搜索成功的
数据
属性,但没有人真正谈论过这种情况。大多数人说它不能与框架一起工作


提前感谢您的帮助/建议。

您找到解决方案了吗?