簡體   English   中英

使用 google-signin 成功登錄后如何重定向

[英]How to redirect after a successful login with google-signin

我正在使用谷歌登錄我的網站。 我已經關注了這個鏈接,所以我的代碼如下所示。 我試圖讓它在成功登錄后重定向到我的索引頁面,我該怎么做?

<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> ```

您可以在成功登錄時提及此行 - window.location.href='#您想要重定向到的 url'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM