使用angular实现Google One Tap Login

问题描述 投票:0回答:1

导航条模板.html

   <div id="g_id_onload"
         data-client_id="832#################m921.apps.googleusercontent.com"
         data-cancel_on_tap_outside="false"
         data-login_uri="http://localhost:3010/auth/g-one-tap"
         data-callback="handleCredentialResponse">
    </div>

API得到的响应我是可以验证用户并返回验证后的JWT令牌的,如何才能捕获响应并避免页面重定向到 http://localhost:3010/auth/g-one-tap

我如何能使用一些点击功能,在typsecript文件中使用,这可以帮助在以下正常的登录流程,我是用谷歌登录按钮早些时候。

 public socialSignIn(responseData) {
         this.googleSubscription = this._globalService.googleLogin(responseData)
                .subscribe(
                    data => {
                        if (data['success']) {
                            const token = data['data']['token'];

                            if (this.platformId === 'browser') {
                               // login to save the token
                            }

                        }
                    },
                    error => {
                        console.log('error');
                    }
                );
    }
google-oauth google-signin google-authentication
1个回答
1
投票

如前所述 此处你不应该同时使用data-login_uri和data-calbck属性。

你需要在你的代码中删除data-login_uri属性,并提供一个回调函数的实现(在你的代码中名称为handleCredentialResponse),如果还没有的话。

© www.soinside.com 2019 - 2024. All rights reserved.