首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用google-signin成功登录后重定向

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

Stack Overflow用户
提问于 2020-06-24 15:14:56
回答 1查看 433关注 0票数 0

我正在使用谷歌的登录我的网站。我已经跟踪了this链接,所以我的代码如下所示。我试图在成功登录后将其重定向到我的索引页面,我该如何做?

代码语言:javascript
复制
<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> ```
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-24 15:19:07

您可以在成功登录时提到这一行-window.location.href=‘#要重定向到的url’

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62549661

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档