0

我正在使用谷歌登录我的网站。我已经关注了 这个链接,所以我的代码如下所示。我试图让它在成功登录后重定向到我的索引页面,我该怎么做?

<head>
    <meta name="google-signin-client_id" content="My_client_id.apps.googleusercontent.com">
    <script src="https://apis.google.com/js/platform.js" async defer></script>
    <meta name="google-signin-scope" content="profile email">
</head>

<div class="mx-auto" id="my-signin2"></div>        
<script>
    function onSuccess(googleUser) {
        console.log('Logged in as: ' + googleUser.getBasicProfile().getName());        
    }
    function onFailure(error) {
        console.log(error);
    }
    function renderButton() {
        gapi.signin2.render('my-signin2', {
            'scope': 'profile email',
            'width': 240,
            'height': 50,
            'longtitle': true,
            'theme': 'dark',
            'onsuccess': onSuccess,
            'onfailure': onFailure
        });
    }
    function onSignIn(googleUser) {        
        // Useful data for your client-side scripts:
        var profile = googleUser.getBasicProfile();
        console.log("ID: " + profile.getId()); // Don't send this directly to your server!
        console.log('Full Name: ' + profile.getName());
        console.log('Given Name: ' + profile.getGivenName());
        console.log('Family Name: ' + profile.getFamilyName());
        console.log("Image URL: " + profile.getImageUrl());
        console.log("Email: " + profile.getEmail());

        // The ID token you need to pass to your backend:
        var id_token = googleUser.getAuthResponse().id_token;
        console.log("ID Token: " + id_token);       
      }
</script>
<script src="https://apis.google.com/js/platform.js?onload=renderButton" async defer></script> ```
4

1 回答 1

1

您可以在成功登录时提及这一行 - window.location.href='#the url you want to be redirected to'

于 2020-06-24T07:19:06.670 回答