我如何迁移我的旧 javascript google 新 sdk 注册按钮

How i migrate my old javascript google sign up button for new sdk

我想为新的身份 sdk 迁移旧的 google 注册按钮。我在我的项目中包含了新的按钮代码,但我不知道如何编辑我的旧 javascript 代码。我的按钮代码:

<div id="g_id_onload"
    data-client_id="key"
    data-context="use"
    data-ux_mode="popup"
    data-callback="onSignIn"
    data-auto_prompt="false">
</div>

<div class="g_id_signin"
    data-type="standard"
    data-shape="rectangular"
    data-theme="outline"
    data-text="signin_with"
    data-size="large"
    data-logo_alignment="left">
</div>

我的旧 javascript 代码:

function onSignIn(googleUser) {
    var profile = googleUser.getBasicProfile();

    $("#user").text(profile.getName());
    $("#email").text(profile.getEmail());
    $("#gPhoto").attr("src", profile.getImageUrl());
}

新的google身份服务将在成功登录后提供令牌作为jwt(json网络令牌),您可以在javascript中解码如下...

    function onSignIn(googleUser){
    //here onSignIn is your call back function name
    var token=googleUser.credential;
    var userinfo=JSON.parse(atob(token.split('.')[1]));
var i,e,n,p
    i=userinfo['sub']; //ID
    e=userinfo['email'];
    n=userinfo['name'];
    p=userinfo['picture'];
    alert(e);
    alert(i);
    alert(n);
    alert(p);
    }